Skip to content

fix: report an msnodesqlv8 request timeout as ETIMEOUT - #1990

Merged
dhensby merged 1 commit into
tediousjs:masterfrom
dhensby:fix/msnodesqlv8-timeout-code
Nov 27, 2026
Merged

dhensby merged 1 commit into
tediousjs:masterfrom
dhensby:fix/msnodesqlv8-timeout-code

Conversation

@dhensby

@dhensby dhensby commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

What this does:

On msnodesqlv8, a request that runs past its requestTimeout fails with the code EREQUEST and the error number 0. That is what msnodesqlv8 gives the ODBC error HYT00 (query timeout expired). tedious reports the same timeout with the code ETIMEOUT and no error number, and the README lists ETIMEOUT for each kind of request, with no exception for msnodesqlv8.

An error with SQLSTATE HYT00 now has the code ETIMEOUT and no error number, as on tedious. It keeps the message of the driver, and its state is still HYT00.

field tedious msnodesqlv8 before msnodesqlv8 after
code ETIMEOUT EREQUEST ETIMEOUT
number undefined 0 undefined
state undefined HYT00 HYT00
message Timeout: Request failed to complete in 1000ms Query timeout expired Query timeout expired

This covers query(), execute(), batch(), prepared statements, streams and the statement that bulk() uses to create a table. A TransactionError from begin, commit or rollback takes the code of the request, so it is ETIMEOUT too, as on tedious.

Not changed:

Code that checks err.code === 'EREQUEST' to find an msnodesqlv8 timeout no longer matches. Such code can check err.code === 'ETIMEOUT', which works on both drivers.

Live results:

SQL Server 2022 Developer on an Azure Windows Server 2022 VM, with requestTimeout: 1000 and waitfor delay '00:00:05'. I tested msnodesqlv8 2.7.0 (Node 18), 3.1.0 and 4.5.0 (Node 20), 5.6.0 (Node 22) and 6.2.2 (Node 22 and 24). I ran each one with SQL Server Native Client 11.0 (the default on Windows) and with ODBC Driver 17.

case master this branch
query(), batch(), execute(), a prepared statement, a stream, a request in a transaction, a timeout after raiserror, a bulk() whose create table is blocked by another session EREQUEST, number 0, state HYT00 ETIMEOUT, no number, state HYT00
a query on the same pool after the timeouts runs runs

The results are the same on each version and each ODBC driver. tedious 19.2.2 on the same server gives ETIMEOUT with no number in all eight cases.

  • With this branch, npm run test-msnodesqlv8 passes on all six version pairs (195 to 198 passing, 0 failing).
  • I ran the timeout integration tests from this branch against the master code (msnodesqlv8 6.2.2, Node 24). All 9 fail, with 'EREQUEST'.
  • When raiserror comes before the timeout, msnodesqlv8 does not report the raiserror error at all, on master or on this branch. tedious keeps it in precedingErrors. This change does not affect that.

Tests:

  • Unit (msnodesqlv8 query events harness): query(), execute(), batch(), a stream, a timeout after a server error that does not end the batch, and a bulk load whose create table times out. Four existing tests that expected EREQUEST or the number 0 for HYT00 now expect ETIMEOUT, including the transaction begin test. One test checks that HYT01 stays EREQUEST. Ten of these fail on master.
  • Integration: the request timeout tests in test/common/tests.js now check that code is ETIMEOUT on both drivers.
  • Locally, npm test passes (562 unit tests). npm run test-tedious gives 225 passing and 5 pending. Three tests fail on master too: user defined types and the two spatial/hierarchyid bulk loads. They fail because the local server is Azure SQL Edge, which has no CLR.

Related issues:

Found by an audit of @types/mssql against 12.8.1. Related to #1974, which this does not change.

Pre/Post merge checklist:

  • Update change log

🤖 Generated with Claude Code

On msnodesqlv8, a request that ran past its requestTimeout failed with
the code EREQUEST and the error number 0. That is the number that
msnodesqlv8 gives the ODBC error HYT00 (query timeout expired). tedious
reports the same timeout with the code ETIMEOUT and no error number,
and the README lists ETIMEOUT for each kind of request.

An error with SQLSTATE HYT00 now has the code ETIMEOUT and no error
number. It keeps the message of the driver, and its state is still
HYT00. This covers query(), execute(), batch(), prepared statements,
streams and the statement that bulk() uses to create a table. A
TransactionError from begin, commit or rollback takes the code of the
request, so it is ETIMEOUT too, as on tedious.

A connection timeout (HYT01) stays EREQUEST: tedious has no error like
it. msnodesqlv8's own timer on Linux with ODBC Driver 17 ends a query
as cancelled, with no HYT00 error, so this change does not reach it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhensby
dhensby marked this pull request as ready for review November 27, 2026 23:38
@dhensby
dhensby merged commit ce685a5 into tediousjs:master Nov 27, 2026
93 of 94 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 12.8.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant