The pre-fetch resource mechanism of the Chrome browser causes a request to send two times and the clientabortexception exception

Source: Internet
Author: User

Investigate a PDF print error: caused Connection Abort:socket Write Errorat org.apache.catalina.connector.OutputBuffer.realWriteBytes ( : 407) at Org.apache.tomcat.util.buf.ByteChunk.flushBuffer ( at Org.apache.tomcat.util.buf.ByteChunk.append ( at Org.apache.catalina.connector.OutputBuffer.writeBytes ( at Org.apache.catalina.connector.OutputBuffer.write ( at Org.apache.catalina.connector.CoyoteOutputStream.write ( at (Unknown Source) at Com.itextpdf.text.pdf.OutputStreamCounter.write ( at (Unknown Source) at COM.ITEXTPDF.TEXT.PDF.PDFSTREAM.TOPDF ( at Com.itextpdf.text.pdf.PdfIndirectObject.writeTo ( at Com.itextpdf.text.pdf.pdfwriter$pdfbody.add ( at Com.itextpdf.text.pdf.pdfwriter$pdfbody.add ( at com.itextpdf.text.pdf.pdfwriter$ Pdfbody.add ( at Com.itextpdf.text.pdf.PdfWriter.addToBody ( at Com.itextpdf.text.pdf.TrueTypeFontUnicode.writeFont ( at Com.itextpdf.text.pdf.FontDetails.writeFont ( at Com.itextpdf.text.pdf.PdfWriter.addSharedObjectsToBody ( at Com.itextpdf.text.pdf.PdfWriter.close ( at Com.itextpdf.text.pdf.PdfDocument.close ( at Com.itextpdf.text.Document.close (

You can see that an appeal error was thrown when the Document.close () method of the PDF was called.

After debugging the reason is that in the Chrome browser page to print, print servlet will do two times, the first time can print normally, document.close () can be normal execution, no error, can be executed, the servlet once again executed! So at the second document.close (), the error: caused connection Abort:socket write error

The reason is that the browser has closed the connection, so the second time to the browser output:

Response.setcontenttype ("Application/pdf");

, the error is only.

Only chrome is found to be the problem. Results of the survey:


Post the full text:

The pre-fetch resource mechanism of chrome and other browsers causes a request to send a two-time problem with a clientabortexception exception

Bloggers in writing a file download blog, encountered a very disgusting problem, the phenomenon is I in the Chrome and Safari browser address bar directly input file download link localhost : 8080/download, my download method was requested two times and the first time the following Clientabortexception exception was thrown

Then Chrome got a lot of information and finally found the reason: because Chrome, Safari and other browsers in order to make the Web page loading faster, using a kind of called prefetch resources to more quickly load the page mechanism, that is, when you enter the URL in the browser, even if you did not return to send a request, The browser will also pre-send the request to load the resource, so whenever I enter the URL localhost:8080/download in the address bar, the browser sends a request to my download method, and then my download method returns a file download response to the browser, at which point , the browser is a file download, can not be preloaded, so the initiative to close the link, causing the clientabortexception exception, and then I return to the real send the request, the browser will download the file, there is no exception, the file download is successful. The result is a two-time request from chrome.

The process of finding information on the Internet, see some people doing counting statistics, if you use chrome, each request accounting two times, in fact, it is also caused by the problem, so if you in the process of development, if you encounter a request to send a number of questions, you might consider, close Chrome's pre-extracted resources function tests, often to solve the problem. This problem is very disgusting, and not easy to detect, I hope this article can be helpful to Yimeimei.


The pre-fetch resource mechanism of the Chrome browser causes a request to send two times and the clientabortexception exception

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.