Skip to content
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

Detecting if a client is still connected while processing a request #1249

Open
jacky309 opened this issue Oct 10, 2024 · 4 comments
Open

Detecting if a client is still connected while processing a request #1249

jacky309 opened this issue Oct 10, 2024 · 4 comments

Comments

@jacky309
Copy link

jacky309 commented Oct 10, 2024

While processing a request, is it possible to be somehow notified (even with some polling) if the client connection has been closed, in order to stop the processing earlier, if we are not going to be able to send the response anyway ?

@dgreatwood
Copy link
Contributor

dgreatwood commented Oct 11, 2024 via email

@jacky309
Copy link
Author

jacky309 commented Oct 11, 2024

The early termination would be useful to avoid "consuming" one server thread for a client which is already disconnected anyway, since the way the request is currently processed is basically via a while loop inside our request handler, which does not end until the client has disconnected. We have been able to implement that mechanism with a patched version of Pistache, but we would like to get rid of that patch now.
I am not yet very familiar with Pistache, but I believe that it is allowed to copy/move the Pistache::Http::ResponseWriter object which we get in our request handler method, exit the handler (releasing the server thread), and use the copied Pistache::Http::ResponseWriter object later (from another thread of ours) to provide the request response. Is my understanding right ?

@kiplingw
Copy link
Member

kiplingw commented Oct 11, 2024

@jacky309, you might want to look at Pistache's support for streaming a continuous response to the client. I've never used it personally, but it might solve your problem. I don't know how it handles the socket being closed by the client, but whoever wrote that code probably already contemplated that scenario.

@dgreatwood
Copy link
Contributor

dgreatwood commented Oct 11, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants