Skip to content

Commit 6b4029d

Browse files
committed
review: measure stream lifetime with monotonic performance.now()
Date.now() can step backwards (NTP correction, VM pause), which could misclassify a healthy long-lived stream as fruitless. performance.now() is monotonic, already used for durations in middleware.ts, and available in all target runtimes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Eqc26ABfbhTimyUUszsUxL
1 parent b0d2ee7 commit 6b4029d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

packages/client/src/client/streamableHttp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ export class StreamableHTTPClientTransport implements Transport {
792792
// keeping repeated connect/idle-close cycles bounded by `maxRetries`
793793
// (#2682).
794794
let receivedMessage = false;
795-
const streamOpenedAt = Date.now();
795+
const streamOpenedAt = performance.now();
796796

797797
// Single scheduling site for both the graceful-close and the
798798
// mid-stream-error paths below — the #2682 bug existed precisely
@@ -810,7 +810,7 @@ export class StreamableHTTPClientTransport implements Transport {
810810
// looping forever (#2682). Priming events alone deliberately do
811811
// not reset the count — a server can send one and still close
812812
// immediately, which would re-arm exactly that loop.
813-
const madeProgress = receivedMessage || Date.now() - streamOpenedAt >= this._reconnectionOptions.maxReconnectionDelay;
813+
const madeProgress = receivedMessage || performance.now() - streamOpenedAt >= this._reconnectionOptions.maxReconnectionDelay;
814814
this._scheduleReconnection(
815815
{
816816
// A reconnected stream that ended before any event arrived

0 commit comments

Comments
 (0)