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

Add {Response,DataSink}::is_alive #1956

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

ochafik
Copy link

@ochafik ochafik commented Oct 4, 2024

This is to be able to detect if the client connection was lost.

Context: #1952 / ggerganov/llama.cpp#9679

As suggested by @ngxson, since is_writable / select_write may be a bit heavyweight, I tried using just select_read (given it's in a context when every other thread is done reading) but it didn't do the trick alone, so settled for is_socket_alive (which uses select_read + read_socket): seems to work.

Update: I finally realized having is_alive on DataSink isn't enough, so moved it to Response itself (by lack of a better place?). In the llama.cpp use case we need to test for liveness before status / headers are even written back. Added a tiny test to exercise this.

Tested (no new failures): cmake -B build -DHTTPLIB_TEST=1 -DHTTPLIB_REQUIRE_OPENSSL=0 -DHTTPLIB_COMPILE=1 -DHTTPLIB_TEST=1 -DHTTPLIB_REQUIRE_ZLIB=1 -DHTTPLIB_REQUIRE_BROTLI=1 && cmake --build build -j && ctest --test-dir build -j

@ochafik ochafik marked this pull request as ready for review October 4, 2024 18:30
@ochafik ochafik changed the title Add {Stream,DataSink}::is_alive Add {Response,DataSink}::is_alive Oct 5, 2024
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.

1 participant