-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Xian Li opened SPR-13126 and commented
javax.servlet.ServletResponse#getWriter will return java.io.PrintWriter.
Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError().
But the renders of popular templates (FreeMarker/Velocity) just use java.io.Writer and expect an IOException thrown if something is wrong.
This mismatch will lead the render writes data continuously while the connection has been broken.
I have met a bug while using default Jetty 8 and FreeMarker. If the client close the connection, The render will write data continuously and the Jetty 8 continuously flush a full buffer. This will lead a performance issue dramatically.
Fixing It depends on the servlet container to return a subclass of java.io.PrintWriter, which can handle exception properly while the connection is broken and the render don't known that.
For popular containers:
- Jetty 8 will swallow the
IOExceptionby default, while you can config to use aUncheckedPrintWriter. - Jetty 9 (latest 9.2.11.v20150529) swallow the
IOExceptionby default, and you can't change it. This bug has been fixed and will release in jetty 9.3. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=465754) - Tomcat will swallow the
IOException. But it will abandon the Writer and do nothing further.
But I think maybe the spring framework has the responsibility to handle it because the contract of the ServletResponse declare PrintWriter. You should not assume the web container has handled the mismatch properly.
Affects: 4.2 RC1