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
Fix Stream Callback never being called in close #2905
Conversation
…esponse starts streaming
@@ -50,13 +50,17 @@ final class HTTPServerHandler: ChannelInboundHandler, RemovableChannelHandler { | |||
if !keepAlive { | |||
context.close(mode: .output, promise: nil) | |||
} | |||
case .failure(ChannelError.ioOnClosedChannel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quick question: why only when .ioOnClosedChannel
? I would've thought that this needs to be done on any write error. And even if there's no write error but the connection goes away we should notify the user, right?
CC @Lukasa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't errorCaught(context:error:)
function be triggered in all cases as well so the error can be bubbled up and handled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xTim the problem at hand isn't that Vapor doesn't know about the error, it's that the user doesn't learn about it, right? So I'm not sure why other errors aren't handled similarly. Not saying it's wrong, just don't quite follow
Co-authored-by: Dan Appel <Dan.appel00@gmail.com>
if case .stream(let stream) = response.body.storage { | ||
stream.callback(ErrorBodyStreamWriter(eventLoop: request.eventLoop, error: error)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weissi can you see any problem with this? I've taken a look at it and it seems to make sense we should call call errorCaught
and trigger the stream callback if we have them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM... I think 😅
These changes are now available in 4.67.3 |
Fixes a bug where abandoned requests mean that the stream callback is never invoked. This happens when a client sends a request, the server starts processing it but hasn't constructed the
Response
and then the client closes early. The response is discarded, as is the stream callback so it never gets invoked. This fixes that issue