Repository navigation
Fix TimeoutNegativeWarning in event-hubs CBS auth - #38166
Merged
Merged
Conversation
When CBS session setup or lock acquisition takes longer than the original timeout budget, the remaining time computation (timeoutAfterStartTime - Date.now()) goes negative. Node.js v24+ raises a TimeoutNegativeWarning when setTimeout receives a negative value. Fix by clamping timeout values to a minimum of 0 at three layers: - withAuth.ts: Clamp remaining time at each deadline computation - requestResponseLink.ts: Clamp timeoutInMs in sendRequest - lock.ts: Clamp timeoutInMs in acquire's setTimeout Fixes #38163 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deyaa (deyaaeldeen)
requested review from
a team,
Ashish Chhabria (axisc),
Eric Lam (MSFT) (hmlam),
Johnathan W (j7nw4r),
SJ (sjkwak) and
Jeff Fisher (xirzec)
as code owners
April 16, 2026 14:31
Clamp 3 remaining-time computations in linkEntity.ts to Math.max(..., 0) to prevent TimeoutNegativeWarning on Node.js v24+. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deyaa (deyaaeldeen)
requested review from
Eldert Grootenboer (EldertGrootenboer) and
Srini Karri (skarri-microsoft)
as code owners
April 16, 2026 14:35
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents Node.js v24+ TimeoutNegativeWarning in Event Hubs CBS authentication by ensuring negative timeout values never flow into setTimeout() (and related timeout-based operations) when the overall deadline has already elapsed.
Changes:
- Clamp remaining-time computations in Event Hubs CBS auth (
withAuth.ts) to never go below0. - Clamp
timeoutInMsin@azure/core-amqprequest/responsesendRequest()to never go below0. - Clamp
timeoutInMsin@azure/core-amqplock acquisition timeouts to never go below0.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| sdk/eventhub/event-hubs/src/withAuth.ts | Clamps deadline-derived remaining time to avoid negative values reaching CBS init/claim negotiation paths. |
| sdk/core/core-amqp/src/requestResponseLink.ts | Clamps timeoutInMs used by the request/response timeout setTimeout() to prevent negative timer values. |
| sdk/core/core-amqp/src/util/lock.ts | Clamps timeoutInMs used by lock acquisition timeout setTimeout() to prevent negative timer values. |
- Use ternary for timeoutInMs: undefined uses default, otherwise clamp to 0 - Add test: lock.acquire with negative timeoutInMs rejects with OperationTimeoutError - Add test: sendRequest with negative timeoutInMs times out immediately Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The previous version 7.10.0-beta.4 was already released. Increment to beta.5 so the changelog entry for the negative timeout fix is in the correct unreleased section. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deyaa (deyaaeldeen)
force-pushed
the
fix/negative-timeout-warning
branch
from
April 16, 2026 16:26
6722eec to
69d309a
Compare
Add Math.max(timeoutInMs, 0) to setTimeout in CancellableAsyncLockImpl to prevent Node.js TimeoutNegativeWarning. Add test verifying negative timeout rejects immediately with OperationTimeoutError. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deyaa (deyaaeldeen)
force-pushed
the
fix/negative-timeout-warning
branch
from
April 16, 2026 16:32
69d309a to
4a7c724
Compare
Jeff Fisher (xirzec)
approved these changes
Apr 16, 2026
Jeff Fisher (xirzec)
left a comment
Member
There was a problem hiding this comment.
Changes to core look good
|
|
||
| ### Other Changes | ||
|
|
||
| - Performance improvements for event reception and transmission: replaced polling-based event detection with event-driven queue signals, simplified message serialization path, and optimized EventData cloning logic. These changes reduce latency for event detection by ~200x and improve overall throughput. [#37882](https://github.com/Azure/azure-sdk-for-js/pull/37882) |
Member
There was a problem hiding this comment.
seems like we lost this changelog message?
Member
Author
There was a problem hiding this comment.
I don't see this in the PR diff.
The performance improvements entry was accidentally merged with the bug fix entry. Restore the Other Changes section with its original content. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deyaa (deyaaeldeen)
marked this pull request as draft
April 16, 2026 17:20
Replace try/catch/assert.fail patterns with expect().rejects.toThrow() in lock and requestResponse tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deyaa (deyaaeldeen)
marked this pull request as ready for review
April 16, 2026 20:20
Deyaa (deyaaeldeen)
force-pushed
the
fix/negative-timeout-warning
branch
from
April 21, 2026 23:55
2a5b748 to
4ab48ab
Compare
Deyaa (deyaaeldeen)
force-pushed
the
fix/negative-timeout-warning
branch
from
April 22, 2026 01:22
4ab48ab to
60b7929
Compare
Deyaa (deyaaeldeen)
added a commit
that referenced
this pull request
Apr 22, 2026
…38246) ## Release Preparation Sets release date to **2026-04-22** for both packages and finalizes changelogs. ### @azure/core-amqp 4.4.2 - **Bug fix**: Handle `AggregateError` in `translate()` for Node.js 20+ Happy Eyeballs (#38233) - **Bug fix**: Clamp negative `setTimeout` values to 0 for Node.js v24+ (#38166) ### @Azure/event-hubs 6.0.4 - **Bug fix**: Clamp negative timeout computations to 0 for Node.js v24+ (#38166) - **Perf**: Event-driven queue signals, simplified serialization, optimized cloning (#37882) --------- Co-authored-by: Deyaa Eldeen <deyaaeldeen@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Summary
Fixes
TimeoutNegativeWarningraised by Node.js v24+ whensetTimeoutreceives a negative timeout value.#38163
Root Cause
In
sdk/eventhub/event-hubs/src/withAuth.ts, a deadline pattern computes remaining time astimeoutAfterStartTime - Date.now(). If prior steps (opening CBS session, acquiring lock) consume more time than the original timeout budget, this goes negative. The negative value flows intosetTimeout()inrequestResponseLink.sendRequest()andlock.acquire(), triggering:This is cosmetic — Node clamps to 1ms and the operation succeeds — but the warning triggers ops alerts.
The same pattern exists in Service Bus's
linkEntity.ts.Fix
Clamp timeout values to
Math.max(..., 0)at all affected sites (defense in depth):sdk/eventhub/event-hubs/src/withAuth.tstimeoutAfterStartTime - Date.now()sdk/servicebus/service-bus/src/core/linkEntity.tstimeoutInMs - (Date.now() - startTime)sdk/core/core-amqp/src/requestResponseLink.tstimeoutInMsinsendRequest()sdk/core/core-amqp/src/util/lock.tstimeoutInMsinacquire()'ssetTimeout