Repository navigation
fix(eio-client): honor the requestTimeout option in Node.js and with fetch() - #5611
Open
mark1russell7 wants to merge 1 commit into
Open
mark1russell7 wants to merge 1 commit into
mark1russell7 wants to merge 1 commit into
Conversation
…fetch() The requestTimeout option was only applied through the "timeout" attribute of the XMLHttpRequest object, which is not supported by the "xmlhttprequest-ssl" package (the default polling implementation in Node.js), and was ignored by the Fetch transport. A request that never received a response stayed pending forever. The XHR request now handles the timeout itself when the XMLHttpRequest implementation does not support it, and the Fetch transport aborts the request with an AbortController. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The kind of change this PR does introduce
Current behavior
The
requestTimeoutoption is applied withxhr.timeout = requestTimeout. This works with theXMLHttpRequestobject of a browser only: thexmlhttprequest-sslpackage (the default polling transport in Node.js) has notimeoutattribute, and theFetchtransport ignores the option. A request that never gets an answer leaves the socket in theopening(oropen) state with no error.New behavior
Fetch: whenrequestTimeoutis set, each request gets the signal of anAbortControllerthat is aborted afterrequestTimeoutms. The timer is cleared when the response headers are received (asxhr.timeoutdoes not apply to the body read either). The rejection goes to the existingfetch read error/fetch write errorpath.requestTimeoutis set and theXMLHttpRequestobject has noontimeoutattribute (the case ofxmlhttprequest-ssl), the request starts its own timer. When it fires, the request emitserror(status0, the same value as a browser timeout) and is cleaned up. The timer is cleared in_cleanup(), and it is unref'd whenautoUnrefis set.In the XHR timer,
xhr.abort()is not called: withxmlhttprequest-ssl2.1.2 and later (the version that~2.1.1installs), aborting a pending request throws an uncaughtTypeError: Cannot read properties of null (reading 'reusedSocket')(mjwwit/node-XMLHttpRequest#37). The lock file of this repository has 2.1.1, which does not have this problem, so a test in this repository would not show it. The request is only detached, so its connection stays open until the server answers or closes it.Other information (e.g. related issues)
Fixes #5610
The new test in
test/node.js("should abort the request after requestTimeout ms (polling)") uses an HTTP server that never answers, and a socket withrequestTimeout: 100. It expects anerrorevent (xhr poll error, orfetch read errorwithUSE_FETCH=1) and acloseevent with the reasontransport error.Test results:
lib/folder ofmain(545e984) with the tests of this branch.xmlhttprequest-ssl)USE_FETCH=1Full Node.js suites of the branch:
test/index.js99 passing, 1 pending (USE_FETCH=1: 98 passing, 2 pending);mainhas 98 and 97 passing.test/webtransport.mjs: 10 passing, 1 failing (see below).prettier --checkpasses on the changed files.The failure in
test/webtransport.mjsalso happens onmainin this environment: "should send some binary data (server to client) (as ArrayBuffer)" (a timeout of 2000 ms). Onmain, "should allow to upgrade to WebTransport" also failed with a timeout in the same run.The issue repro was also run with
xmlhttprequest-ssl2.1.2 (the version that~2.1.1installs): the socket emitserrorandcloseafter the timeout, with no exception.This PR was prepared with AI assistance (Claude). The tests named above were run before and after the change, with the results above.
🤖 Generated with Claude Code