Skip to content

Fix TimeoutNegativeWarning in event-hubs CBS auth - #38166

Merged
Deyaa (deyaaeldeen) merged 9 commits into
mainfrom
fix/negative-timeout-warning
Apr 22, 2026
Merged

Deyaa (deyaaeldeen) merged 9 commits into
mainfrom
fix/negative-timeout-warning

Conversation

@deyaaeldeen

@deyaaeldeen Deyaa (deyaaeldeen) commented Apr 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes TimeoutNegativeWarning raised by Node.js v24+ when setTimeout receives a negative timeout value.

#38163

Root Cause

In sdk/eventhub/event-hubs/src/withAuth.ts, a deadline pattern computes remaining time as timeoutAfterStartTime - 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 into setTimeout() in requestResponseLink.sendRequest() and lock.acquire(), triggering:

TimeoutNegativeWarning: -1 is a negative number.
Timeout duration was set to 1.

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):

File Sites Change
sdk/eventhub/event-hubs/src/withAuth.ts 4 Clamp timeoutAfterStartTime - Date.now()
sdk/servicebus/service-bus/src/core/linkEntity.ts 3 Clamp timeoutInMs - (Date.now() - startTime)
sdk/core/core-amqp/src/requestResponseLink.ts 1 Clamp timeoutInMs in sendRequest()
sdk/core/core-amqp/src/util/lock.ts 1 Clamp timeoutInMs in acquire()'s setTimeout

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>
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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 below 0.
  • Clamp timeoutInMs in @azure/core-amqp request/response sendRequest() to never go below 0.
  • Clamp timeoutInMs in @azure/core-amqp lock acquisition timeouts to never go below 0.

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.

Comment thread sdk/eventhub/event-hubs/src/withAuth.ts Resolved
Comment thread sdk/core/core-amqp/src/util/lock.ts Resolved
Deyaaeldeen Almahallawi and others added 2 commits April 16, 2026 14:48
- 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>
@deyaaeldeen
Deyaa (deyaaeldeen) force-pushed the fix/negative-timeout-warning branch from 6722eec to 69d309a Compare April 16, 2026 16:26
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>
@deyaaeldeen
Deyaa (deyaaeldeen) force-pushed the fix/negative-timeout-warning branch from 69d309a to 4a7c724 Compare April 16, 2026 16:32

@xirzec Jeff Fisher (xirzec) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we lost this changelog message?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
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>
@deyaaeldeen
Deyaa (deyaaeldeen) marked this pull request as ready for review April 16, 2026 20:20
@deyaaeldeen
Deyaa (deyaaeldeen) force-pushed the fix/negative-timeout-warning branch from 2a5b748 to 4ab48ab Compare April 21, 2026 23:55
@deyaaeldeen
Deyaa (deyaaeldeen) force-pushed the fix/negative-timeout-warning branch from 4ab48ab to 60b7929 Compare April 22, 2026 01:22

@jeremymeng Jeremy Meng (jeremymeng) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@deyaaeldeen
Deyaa (deyaaeldeen) merged commit b2ba4f4 into main Apr 22, 2026
13 checks passed
@deyaaeldeen
Deyaa (deyaaeldeen) deleted the fix/negative-timeout-warning branch April 22, 2026 17:11
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants