Skip to content

fix: prevent Net::ReadTimeout on reused TCP connections#41

Merged
Kaevan89 merged 4 commits into
veryfi:mainfrom
andresgarcia-verify:fix/stale-connection-read-timeout
Jul 3, 2026
Merged

fix: prevent Net::ReadTimeout on reused TCP connections#41
Kaevan89 merged 4 commits into
veryfi:mainfrom
andresgarcia-verify:fix/stale-connection-read-timeout

Conversation

@andresgarcia-verify

Copy link
Copy Markdown
Contributor

Memoising the Faraday connection with @_conn ||= caused the adapter to reuse the same TCP socket across sequential requests. When the Veryfi API server closed a keep-alive connection after a heavy bank-statement upload, the next request attempted to write to an already-closed socket, raising:

Net::ReadTimeout with #TCPSocket:(closed)

Fix: remove the memoisation so every request builds a fresh Faraday connection (and therefore a fresh TCP socket). The overhead of an extra TCP handshake (~50 ms) is negligible compared to the seconds each document-processing request takes.

Also aligns the default timeout with veryfi-python (30 s → was 20 s) and adds a regression spec asserting that #conn never returns a cached object.

Closes #

…y in Veryfi::Request. Update version to 4.0.1.
@andresgarcia-verify
andresgarcia-verify force-pushed the fix/stale-connection-read-timeout branch from 78c117c to 4d929f9 Compare July 3, 2026 16:04
…tale connection recovery. Introduce attempt_request method to manage retries on Faraday::TimeoutError. Update tests to reflect new error handling behavior.
…net_http to 3.4.4, and json to 2.20.0 for improved compatibility and security.
@Kaevan89
Kaevan89 merged commit 11cafb0 into veryfi:main Jul 3, 2026
6 checks passed
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.

2 participants