Fix intermittent "Trying to reuse unacquired resource" on HTTP/2 fetches #22
Loading…
Reference in a new issue
No description provided.
Delete branch "armin-bot/impress:claude/intelligent-goodall-ucr48y"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes the intermittent 500 from the production load test:
raised from
DTIRequests.getwhile fetching manifests from images.neopets.com (7 times in ~56k requests).Root cause
It's a bug in
async-pool0.11.1 (the connection pool under async-http), which upstream has already fixed. The fix here is a lockfile bump to async-pool 0.12.0. async-http 0.89's~> 0.9constraint already allows it, so nothing else moves.The path:
Async::HTTP::Internet.instance, so their manifest fetches multiplex streams over one shared HTTP/2 connection to images.neopets.com.acquire_or_create_resourcechecksviable?, which for HTTP/2 peeks the socket, sees the FIN, and returns false. In 0.11.1 the pool then retires the connection on the spot, even though F is still using it: it deletes the connection from@resources, then starts closing it.reusable?is still true, andreuselooks it up in@resources, finds nothing, and raises. ("0 active streams": F's own stream had already finished.)async-pool 0.11.2 made
reusetolerate an already-retired resource. 0.12.0 goes further: it stops handing out a non-viable resource, but only retires it once its last user releases it, which removes the race outright.The brief's first theory (the pool's "gardener" task is parented to a request, and gets stopped and drains the pool when that request ends) doesn't hold up. The gardener is
transient, and async'sstop_childrenskips transient tasks. When its parent finishes, it's reparented upward rather than stopped (async 2.35node.rb). So I leftDTIRequestsand the sharedInternetinstance alone: cross-request connection reuse wasn't the problem, it just made the race reachable.What's confirmed: the error and the code path, both variants of it:
Trying to reuse unacquired resourceon 0.11.1 and passes on 0.12.0.closeyields while stopping the reader task). That script drives pool internals directly, so it isn't checked in as a spec. 0.12.0 fixes both.What's inferred: the trigger in production, i.e. why images.neopets.com connections stop looking viable. My guess is the server or CDN recycling connections (e.g. a per-connection request cap like nginx's
keepalive_requests, or an idle timeout). I couldn't make that happen organically over localhost: the reader always processes the hang-up before another fiber checks the connection. A narrow, latency-dependent window fits a 7-in-56k rate. Even so, the spec stubsviable?rather than reproducing the hang-up for real.Changes
Gemfile.lock/vendor/cache: async-pool 0.11.1 → 0.12.0.spec/lib/http2_connection_pool_spec.rb: regression spec. It starts a local HTTP/2 server, puts one slow response mid-body, marks its connection non-viable, and checks that a second request gets a fresh connection while the first one finishes cleanly.Testing
bundle exec rspec: 407 examples, 0 failures (2 pending, as before).🤖 Generated with Claude Code
https://claude.ai/code/session_014PWWcywsHc4nxSKJGptZa6