-
Notifications
You must be signed in to change notification settings - Fork 38.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition in error handling for ClientAbortException within a StreamingResponseBody on Tomcat #33439
Comments
Indeed, when a connection is lost while writing, there is an inherent race between the Servlet container initiating error handling (to complete request handling and release resources), as well as the application trying to do the same because of the There is not much we can do to ensure which goes first, and we cannot ensure that one is preferred over the other. Once we exit the Servlet container onError notification, it assumes the error is handled. We cannot hold it up indefinitely either, and there is no guarantee the application will propagate the In summary, you will need to be prepared to handle the root cause, which can also occur for non-streaming scenarios. We have the |
@rstoyanchev we encountered something similar, and I wonder if this is related to this issue. If that's not the case sorry for interrupting this issue. We use the
Although we swallow the exception within the running thread when refreshing the page within the browser that connects to this SSE resource, the following error is logged (within Tomcat):
I assume the only and required way to suppress this is by adding something like:
Right? If that's not related to this problem, is there any chance of making this a bit more user-friendly or at least adding it to the documentation? |
Affects: 6.1.11, 6.2.0-M7
When a
ClientAbortException
occurs within a Spring MVCStreamingResponseBody
sometimes the error handling is not called with the exception thrown by theStreamingResponseBody
, but for the root causejava.io.IOException: Broken pipe
. There seems to be a race condition, as this can be provoked reliably when throwing the exception from theStreamingResponseBody
is delayed by a few milliseconds (see test in example project). This might be only a problem for Tomcat, but I have not yet checked this.As the client aborted the connection the error handling will not be able to send anything to the client, but it can still log things or do other internal stuff. In our case this resulted in unexpected error log entries.
There are some issues that look very related (comments mention a race between Tomcat and the application), but they are closed and the issue still exists with Spring 6.2.0-M7 (I did not see something in the documentation or in a linked issue that this is a know issue for the time being; sorry if I missed it)
For the example project the expected behaviour would be that the error handling is called for the exception throws by the
StreamingResponseBody
:Unexpected is that the error handling is called for the root cause
The text was updated successfully, but these errors were encountered: