Skip to content

test(http-server): guard the prompt stop after a kept-alive request - #713

Merged
andiwand merged 2 commits into
mainfrom
fix/http-server-keep-alive
Aug 20, 2026
Merged

test(http-server): guard the prompt stop after a kept-alive request#713
andiwand merged 2 commits into
mainfrom
fix/http-server-keep-alive

Conversation

@andiwand

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

Closes #641already fixed, this is the test that says so.

#641 reported HttpServer::stop() blocking ~5 s after any request had been served: the accept loop sat in cpp-httplib's keep-alive wait until the client's connection idled out, and stop() waits for listen() to return (rightly — that wait is what makes destruction safe, #633).

The bump to cpp-httplib 0.47.0 in #653 fixed it upstream. In 0.47.0 detail::keep_alive() polls the listening socket and breaks as soon as it is closed, so Server::stop() ends the wait instead of outliving it. That PR measured the same thing from the other side: "serving a rendered view takes 5.03 s on 0.16.3 and 0.03 s on 0.47.0".

Nothing in the suite covered it, so nothing would notice it coming back — a dependency bump or a set_keep_alive_timeout call could reintroduce it silently. This adds the missing coverage:

  • stop_is_prompt_after_serving_a_kept_alive_request serves a request from an httplib::Client that keeps the connection open (and stays alive across the stop(), so the connection really is open there), then times stop().
  • odr_test links httplib::httplib for the client.

Verified

[ RUN      ] HttpServer.stop_is_prompt_after_serving_a_kept_alive_request
[       OK ] HttpServer.stop_is_prompt_after_serving_a_kept_alive_request (12 ms)
[  PASSED  ] 11 tests.

12 ms against the 5.01 s the issue measured; the bound is 2 s, well clear of both.

A kept-alive connection used to hold the accept loop until it idled out,
so `stop()` spanned cpp-httplib's 5 s keep-alive timeout — on the path
every consumer takes, potentially on the main thread while a document
closes. The 0.47.0 bump (#653) fixed it upstream: the keep-alive wait
now watches the listening socket, so closing it ends the wait.

Nothing said so, so nothing would notice it coming back. This serves a
request from a client that keeps the connection open, then times
`stop()`: 12 ms here, against the 5.01 s the issue measured.

`odr_test` links `httplib::httplib` for the client.

Closes #641

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDs5aK3ZGSZsEvqUUwBBXU

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f4216e6cbb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread test/src/http_server_test.cpp
`ASSERT_TRUE(response)` returns from the test with the listen thread
still joinable, and `~std::thread` then calls `std::terminate` — a
transient socket error would abort the whole binary instead of reporting
one failing test. A guard now stops the server and joins on every path;
a second `stop()` is harmless, as the test above it says.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDs5aK3ZGSZsEvqUUwBBXU
@andiwand
andiwand merged commit 8b016b1 into main Aug 20, 2026
36 checks passed
@andiwand
andiwand deleted the fix/http-server-keep-alive branch August 20, 2026 12:13
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.

HttpServer::stop() blocks ~5s after serving a request (cpp-httplib keep-alive timeout)

1 participant