fix(request): destroy request on timeout to prevent indefinite hang#173
Merged
mike-engel merged 1 commit intocustomerio:mainfrom May 7, 2026
Merged
Conversation
Contributor
Author
|
@avigoldman @clabland @karngyan I pushed this change since I’ve been running into a timeout issue. Could you please take a look when you have some time? Thanks! |
mike-engel
approved these changes
May 7, 2026
Collaborator
|
Thanks for your patience @ehduardu! |
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
Setting the timeout option on TrackClient does not actually cause requests to fail after the timeout. https.request only emits a 'timeout' event on socket idleness — it doesn't destroy the request. Since request.ts never registers a 'timeout' listener, the event is ignored and the returned Promise hangs forever.
In practice this means that if Customer.io is slow to respond or a socket becomes half-dead, every caller that awaits the client will hang indefinitely. In our case this caused a RabbitMQ redelivery storm and duplicate email sends to end users.
Fix
Register a 'timeout' handler that destroys the request with a clear error. The existing 'error' handler then rejects the Promise normally.
Test
Added a test that points the client at a server which never responds and asserts the Promise rejects within the configured timeout.
Note
Medium Risk
Changes request lifecycle behavior by destroying the underlying
httpsrequest on sockettimeout, which can affect error handling and retry behavior for all callers. Scope is small and covered by a new unit test, but it impacts a core networking path.Overview
Prevents
CIORequest.handlercalls from hanging indefinitely by adding areq.on('timeout')listener that destroys the request with a clear timeout error message.Adds a focused test to assert the promise rejects when the request emits a socket
timeout, ensuring the timeout option actually fails the request rather than leaving it pending.Reviewed by Cursor Bugbot for commit b16178f. Bugbot is set up for automated code reviews on this repo. Configure here.