Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core-internal/src/shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ export abstract class Protocol<ContextT extends BaseContext> {
}

clearTimeout(info.timeoutId);
info.startTime = Date.now();
info.timeoutId = setTimeout(info.onTimeout, info.timeout);
return true;
}
Expand Down
23 changes: 20 additions & 3 deletions packages/core-internal/test/shared/protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ describe('protocol tests', () => {
onprogress: onProgressMock
});

// First progress notification should work
// First progress notification should work and reset the timeout window
vi.advanceTimersByTime(80);
if (transport.onmessage) {
transport.onmessage({
Expand All @@ -476,7 +476,9 @@ describe('protocol tests', () => {
progress: 50,
total: 100
});
vi.advanceTimersByTime(80);

// Second progress at 101ms later still within maxTotalTimeout (150ms window)
vi.advanceTimersByTime(101);
if (transport.onmessage) {
transport.onmessage({
jsonrpc: '2.0',
Expand All @@ -488,8 +490,23 @@ describe('protocol tests', () => {
}
});
}
await Promise.resolve();

// Third progress at 151ms after the second — exceeds maxTotalTimeout
vi.advanceTimersByTime(151);
if (transport.onmessage) {
transport.onmessage({
jsonrpc: '2.0',
method: 'notifications/progress',
params: {
progressToken: 0,
progress: 90,
total: 100
}
});
}
await expect(requestPromise).rejects.toThrow('Maximum total timeout exceeded');
expect(onProgressMock).toHaveBeenCalledTimes(1);
expect(onProgressMock).toHaveBeenCalledTimes(2);
});

test('should timeout if no progress received within timeout period', async () => {
Expand Down
Loading