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:

ExceptionConverter:org.apache.catalina.connector.ClientAbortException:java.net.SocketException:Software caused Connection Abort:socket Write Errorat org.apache.catalina.connector.OutputBuffer.realWriteBytes (Outputbuffer.java : 407) at Org.apache.tomcat.util.buf.ByteChunk.flushBuffer (bytechunk.java:480) at Org.apache.tomcat.util.buf.ByteChunk.append (bytechunk.java:366) at Org.apache.catalina.connector.OutputBuffer.writeBytes (outputbuffer.java:432) at Org.apache.catalina.connector.OutputBuffer.write (outputbuffer.java:420) at Org.apache.catalina.connector.CoyoteOutputStream.write (coyoteoutputstream.java:91) at Java.io.BufferedOutputStream.write (Unknown Source) at Com.itextpdf.text.pdf.OutputStreamCounter.write ( outputstreamcounter.java:157) at Java.io.ByteArrayOutputStream.writeTo (Unknown Source) at COM.ITEXTPDF.TEXT.PDF.PDFSTREAM.TOPDF (pdfstream.java:353) at Com.itextpdf.text.pdf.PdfIndirectObject.writeTo ( pdfindirectobject.java:157) at Com.itextpdf.text.pdf.pdfwriter$pdfbody.add (pdfwriter.java:396) at Com.itextpdf.text.pdf.pdfwriter$pdfbody.add (pdfwriter.java:376) at com.itextpdf.text.pdf.pdfwriter$ Pdfbody.add (pdfwriter.java:329) at Com.itextpdf.text.pdf.PdfWriter.addToBody (pdfwriter.java:780) at Com.itextpdf.text.pdf.TrueTypeFontUnicode.writeFont (truetypefontunicode.java:385) at Com.itextpdf.text.pdf.FontDetails.writeFont (fontdetails.java:274) at Com.itextpdf.text.pdf.PdfWriter.addSharedObjectsToBody (pdfwriter.java:1249) at Com.itextpdf.text.pdf.PdfWriter.close (pdfwriter.java:1169) at Com.itextpdf.text.pdf.PdfDocument.close ( pdfdocument.java:780) at Com.itextpdf.text.Document.close (document.java:409)

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:

ClientAbortException:java.net.SocketException:Software 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:

-----------------------------------------------------------------------------------------

http://blog.lifw.org/post/66162597

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 http://blog.lifw.org/post/24251622, 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: info-contact@alibabacloud.com 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.