-
Notifications
You must be signed in to change notification settings - Fork 81
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
Raise error on send errors for HTTP/1 responses #359
Conversation
810f30c
to
8d46c58
Compare
8d46c58
to
414ff2a
Compare
Hearing no objections, and having heard back good things on #344, I'm merging this |
Please is there a reason why you keep the connection process alive when the client closes? Can this behavior be a configurable option? For cases where you need well behaved ServerSentEvents (SSE) killing the process is the correct behavior when the client closes. |
It's a side-effect of the process model we use; we don't really have a choice. The key thing is that Bandit only uses a single process per connection, and this connection uses the |
I've used the latest version of Bandit, I setup a test specifically for SSE. THE handling process stays alive, long after the client closes. Is this the expected behavior, for the option 2 you mentioned above?
In this case on the subsequent chunk/2 call for a closed client should see {:error, :closed} ... Yes? |
I'd love to see a repro for this! The SSE process is obviously doing something while it's sitting idle and it may be possible to have it look at the connection status while it's doing this |
(Feel free to reopen this issue, btw) |
Sorry for the delay |
Which client are you using @CharlesOkwuagwu ? I've forked your repo locally and (having changed https to http), connected via
I proceed to see a stream of SSE events sent to the client, as expected. Once I close the client via
Am I missing something here? |
Please open in your web browser (MS-edge) https://localhost:9090/demo |
I see the same behaviour in both Chrome & Safari. Unable to test on Edge, but everything here looks like the server is doing the right thing; I wonder if it's an OS issue (I'm on macOS) or a browser issue? Clients don't always close the underlying connection right away after you close the window, instead keeping it open on a timer for possible reuse. I wonder if that could be what's happening in your case? |
WOW you are right, I Was closing only the tab. When I close the browser. the process exits. Sorry for the disturbance. |
No worries! Glad it all got figured out! |
The Plug spec doesn't really provide for the effective surfacing of errors from send calls, mostly because Cowboy will (usually) have killed off the connection handler process when the client closes the connection. In Bandit's case, we don't actively kill off connection processes in this situation, so we need to be able to surface these cases effectively. Raising a
Bandit.HTTPError
will bubble through the caller all the way up to Bandit's handler pipeline, and log the error as configured. This is as good of a pattern as we're going to have, and mirrors what we do for reads against closed clients already (tests were added for that case here as well, since they were absent before).Fixes #344