Skip to content

Detecting client disconnection #1373

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

Merged
merged 3 commits into from
Aug 31, 2022

Conversation

gh4ck3r
Copy link
Contributor

@gh4ck3r gh4ck3r commented Aug 29, 2022

As described in #1370, Server requires to detect client disconnection if it offers Server-Sent-Event. Unless, it possibly stall the server in certain circumstance. Because if "chunked content provider" which is a component to offer SSE wants to keep connection without sending data, it'll hold given thread as long as given DataSink is "writable". The DataSink, wrapper of SocketStream, uses underlying is_writable() to check it's "writable" of not. But, SocketStream::is_writable() returns true even after disconnection of peer. That means "chunked content provider" can't aware disconnection of client without writing anything.

In this PR, is_writable() of SocketStream and SSLSocketStream returns false if socket is disconnected.

I'll be better to detect half-close status. But, it's not covered here.

This is worked from @AhnLab-OSSG

When the stream is used for SSE server which works via chunked content
provider it's not possible to check connectivity over writability
because it's wrapped by DataSink. It could make the server stalled, when
the provider wants to only keep connection without send data and certain
amount of clients consumes entire threadpool.
SocketStream::is_writable() should return false if peer is disconnected.
DataSink could be unwritable if it's backed by connection based. Because
it could be disconnected by client right after enter centent provider.
@gh4ck3r gh4ck3r changed the title #1370 Detecting client disconnection Detecting client disconnection Aug 29, 2022
@yhirose yhirose merged commit b57f79f into yhirose:master Aug 31, 2022
@yhirose
Copy link
Owner

yhirose commented Aug 31, 2022

@gh4ck3r, thanks for the fine contribution!

@gh4ck3r gh4ck3r deleted the SocketStreamConnectivity branch August 31, 2022 04:56
ExclusiveOrange pushed a commit to ExclusiveOrange/cpp-httplib-exor that referenced this pull request May 2, 2023
* SocketStream need to check connectivity for writability.

When the stream is used for SSE server which works via chunked content
provider it's not possible to check connectivity over writability
because it's wrapped by DataSink. It could make the server stalled, when
the provider wants to only keep connection without send data and certain
amount of clients consumes entire threadpool.

* add unittest for SocketStream::is_writable()

SocketStream::is_writable() should return false if peer is disconnected.

* revise broken unittest ServerTest.ClientStop

DataSink could be unwritable if it's backed by connection based. Because
it could be disconnected by client right after enter centent provider.

Co-authored-by: Changbin Park <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants