-
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
Handle onError events that are sent by the servlet containers [SPR-15614] #20173
Comments
Rossen Stoyanchev commented Taking a closer look, as far as I can see, if an So the Overall So unless leaving it to the container to is an issue for, as it became with timeouts when containers started dispatching even if response status was set (#19233), then I don't see a strong reason for change. What do you think? |
Rossen Stoyanchev commented After some more discussion and experiments (including on the Tomcat mailing list) it's clear that both onTimeout and onError notifications should only be handled from within a container thread, i.e. through the In case of a write error, the server is clearly aware of it and should turn it into a notification. So we can refrain from catching the write exception and calling In order to do that we'll need |
Violeta Georgieva commented Here is the PR |
Prior to this commit, the `ReactiveTypeHandler` would handle `Flux`-like return types from controller methods and adapt them to SSE streams using the `SseEmitter`/`ResponseBodyEmitter` APIs. In case an `IOException` is thrown while writing to the HTTP response stream, the `ReactiveTypeHandler` would rely on the Servlet container to call `AsyncListener#onError` - this would be the signal for Spring MVC to complete the async exchange. To prevent racing issues between this signal and the actual handling of the exception, changes like gh-20173 were applied. Since then, robust checks were added with gh-32340 in `StandardServletAsyncWebRequest.LifecycleHttpServletResponse`. With Jetty 12, `AsyncListener#onError` would not be called as the error would happen while writing in blocking mode to the response (so, not using the Servlet WriteListener contract). But still, such `IOException` would still result in the closing of the HTTP connection. As of Jetty 12.0.4, this is no longer the case and the party managing the async lifecycle is in charge of completing the exchange, as it should. This means that the current behavior leaks HTTP connections for these cases and causes memory issues. This commit ensures that such exceptions happening during response writes are caught and result in the completion of the `SSEEmitter` and the closing of the exchange. Even if other Servlet containers still propagate the error `AsyncListener#onError`, competing signals are still managed with gh-32340. Closes gh-32629
Violeta Georgieva opened SPR-15614 and commented
Hi,
Currently when an I/O error happens,
completeWithError
will be called:https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java#L172
At some point this call will result in:
https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java#L357
Thus the implementation guarantees that the I/O error will be handled properly and the corresponding error handlers will be invoked.
On the other hand there is
AsyncListener
that will be notified by the servlet containers that an error occurred:https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java#L137
This does not trigger any error handling but just completes the async operation.
When the error is I/O then this is not a problem as the implementation handles it as described above, but if it is another type of error then it will not be handled properly.
What do you think?
Regards,
Violeta
Affects: 5.0 RC1
Issue Links:
Referenced from: commits e0678ba
The text was updated successfully, but these errors were encountered: