| Files | Last commit | Last update |
|---|---|---|
fix(server): reclaim idle HTTP connections to prevent fd leaks (#25) A2A::Server::HttpServer tracks every accepted connection in connections_ keyed by fd, but ConnectionContext::lastActivity was only ever written (on accept and on read) and never read: a client that opens a TCP connection and stays silent - or sends a partial request and hangs - kept its entry in connections_ forever, until process exit. On long-running servers this leaks file descriptors until ulimit -n is hit and new connections can no longer be accepted. Changes: - Add ConnectionTimeoutConfig (timeoutSeconds, sweepIntervalSeconds) and expose it through HttpConfig / HttpServerManagerConfig so deployments can tune or disable (timeoutSeconds == 0) idle reclamation. Defaults: 300s timeout, 30s sweep. - Arm a periodic (persistent) timer on the existing libevent event loop in HttpServer::Run(); each tick closes connections whose lastActivity is older than the timeout, reusing CleanupConnection so TLS state is released correctly. - Treat outbound data as activity as well (SendRawResponse refreshes lastActivity) so connections with an ongoing response stream are not reclaimed. - Disarm the timer in Stop() before connections_ is torn down. Tests: unit coverage for the sweep decision (boundary, disabled, mixed set) and interval resolution, plus two end-to-end tests over a real event loop: an idle TCP connection is closed by the sweep, and a connection fed a partial request line every 300ms survives repeated sweeps and is only reclaimed once it goes silent. | 3 days ago |