Uh oh!
There was an error while loading. Please reload this page.
fix: evict pooled connection when a request does not complete (8.0.x) - #539
fix: evict pooled connection when a request does not complete (8.0.x)#539gjtorikian wants to merge 2 commits into
Conversation
Wrap Net::HTTP#request in begin/ensure so that any exit other than a returned response — including exceptions outside StandardError such as an application-level Timeout.timeout or Thread#kill — removes and closes the cached keep-alive connection instead of leaving it mid-stream for the next request on the same thread to pick up. Adds a real-socket regression test plus StubConnection-based coverage of the evict/keep paths, and a teardown that clears the fiber-local connection cache between tests.
Greptile SummaryThis backport makes incomplete HTTP requests evict their pooled sockets, adds regression coverage for exceptional and asynchronous abort paths, and retargets release automation to the v8.0.x maintenance branch.
Confidence Score: 4/5The PR appears safe to merge, with a non-blocking opportunity to limit failure cleanup to the specific timeout-keyed connection that failed. The incomplete-request socket is reliably removed and the release/test changes align with the backport, but endpoint-wide eviction can unnecessarily discard other healthy pooled connections. Files Needing Attention: lib/workos/base_client.rb Important Files Changed
|
| # socket handed back to the pool desyncs the *next* request on this | ||
| # thread, so drop it here rather than in the rescue. | ||
| evict_connection(base) unless request_completed | ||
| end |
There was a problem hiding this comment.
Eviction drops healthy sibling connections
When the same fiber has connections to this endpoint cached with different timeout values, an incomplete request calls evict_connection(base), which closes every timeout-specific entry rather than only the failed socket. Subsequent requests using those healthy entries must reconnect, adding connection and TLS setup latency.
Knowledge Base Used:Core client infrastructure
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/workos/base_client.rb
Line: 153
Comment:
**Eviction drops healthy sibling connections**
When the same fiber has connections to this endpoint cached with different timeout values, an incomplete request calls `evict_connection(base)`, which closes every timeout-specific entry rather than only the failed socket. Subsequent requests using those healthy entries must reconnect, adding connection and TLS setup latency.
**Knowledge Base Used:**[Core client infrastructure](https://app.greptile.com/workos/-/custom-context/knowledge-base/workos/workos-ruby/-/docs/core-client.md)---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Backport to the 8.0 series (targets a
v8.0.2patch release via release-please on this branch).What changed
lib/workos/base_client.rb: wrapNet::HTTP#requestinbegin/ensureand evict the cached keep-alive connection unless the request completed. Any exit other than a returned response — a connection error the rescue below knows about, one it doesn't, or a non-local exit such as an application-levelTimeout.timeoutorThread#kill— now removes and closes the pooled socket instead of leaving it mid-stream for the next request on the same thread.test/workos/test_base_client.rb: adds a real-socket regression test (test_aborted_request_does_not_leak_its_response_to_the_next_request),StubConnection-based coverage of the evict/keep paths, and ateardownthat clears the fiber-local connection cache between tests (this branch predates theThread.current[]storage change in v9.1.0, so the teardown clearsFiber[:workos_connections])..github/workflows/release-please.yml: trigger release-please on pushes tov8.0.xwithtarget-branch: v8.0.x, so merging this PR opens the 8.0.2 release PR automatically.Verification
test/workos/test_base_client.rbsuite passes across multiple seeds (20 runs, 37 assertions).standardrbclean on both changed files.