Harden HTTP server against up-but-not-serving failure modes#11
Merged
Conversation
The agent could stay alive while no longer accepting connections on its HTTP port. Three independent causes are addressed: - Accept loop: async_accept was only re-armed on the success path, so any accept error (fd exhaustion/EMFILE, ECONNABORTED) permanently stopped the listener. Recoverable errors now re-arm after a 100ms backoff; operation_aborted (shutdown) still stops cleanly. - Bind failure: listen() used non-throwing asio overloads and returned silently on error, leaving the process running but never listening. It now throws so start()'s handler logs fatal and exits for supervisor restart. - io_context worker: a throwing completion handler unwound the only worker thread, silencing all async serving. The worker now catches and resumes. Also: Server::fail() now logs the failing-step description (previously discarded), and getAcceptRearmCount() exposes accept-error recoveries for diagnostics. Adds regression tests for each fix (accept re-arm counter 0->1, listen() throws on port conflict, io_context worker survives a thrown handler). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
johnathan-arsenault
requested review from
aprimakDNX,
gmaentz,
npalmerDNX and
nsargentDNX
July 14, 2026 17:29
npalmerDNX
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The agent process could stay alive while no longer accepting connections on its HTTP port. Investigation of the REST sink server lifecycle (
Agent::start→RestService::start→Server::start/listen/accept→AsyncContextworker loop) turned up three independent causes.Root causes & fixes
async_acceptonly on the success path, so any accept error (fd exhaustion/EMFILE,ECONNABORTED) permanently stopped the listener while the process stayed alive. Most likely cause of intermittent "up but not serving" outages.operation_aborted(shutdown) still stops cleanly.start()'stry/catchnever fired, so a failed bind (EADDRINUSE, badServerIp, privileged port) left the process running but never listening.listen()now throws on open/bind/listen/set_option failure →start()logs fatal andstd::exit(1)for supervisor restart.WorkerThreads=1), silencing all async serving while the main thread idled.run()(valid per asio:run()may be re-called after a handler throws).Plus:
Server::fail()now logs the failing-step description (previously discarded, making bind/accept failures undiagnosable), and a newgetAcceptRearmCount()exposes accept-error recoveries for diagnostics.Tests
Genuine regression tests added for each fix:
HttpServerTest.accept_loop_rearms_after_recoverable_error— asserts the re-arm counter goes 0→1 after an injected recoverable accept error. Verified it fails when Fix Jarsenault debify #1 is reverted (counter stays 0) and passes when restored.HttpServerTest.listen_throws_when_port_is_already_bound— assertslisten()throws on a bind conflict.AsyncContextTest.worker_survives_a_thrown_handler(newasync_context_test.cpp) — asserts a second handler still runs after a prior handler throws.Validation
Built and tested via the Ubuntu-22.04 CI-parity Docker image (gcc-13,
-static-libgcc -static-libstdc++— matches edge-device link requirements): 756/756 tests pass, exit 0.Notes for reviewers
🤖 Generated with Claude Code