-
-
Notifications
You must be signed in to change notification settings - Fork 685
Open
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers
Description
Bug Description
MockAgent with delayed responses handle the reply even for aborted controllers, possibly causing an uncaughtException error when an AbortSignal aborted the request.
I noticed this when trying to add the decompress interceptor, which has an assertion of assert(!this.#onErrorCalled) in onResponseStart, which in this case is being called after the controller was aborted.
Reproducible By
const { MockAgent, interceptors: { decompress } } = require('undici');
const agent = new MockAgent().compose(decompress());
const mockPool = agent.get('https://postman-echo.com');
mockPool.intercept({ path: '/delay/30', method: 'GET' }).reply(200, { success: true }, { headers: { 'content-type': 'application/json' } }).delay(30).times(2);
// This works:
const noSignal = await agent.request({ origin: 'https://postman-echo.com', path: '/delay/30', method: 'GET' });
// This raises an uncaughtException
const withSignal = await agent.request({ origin: 'https://postman-echo.com', path: '/delay/30', method: 'GET', signal: AbortSignal.timeout(10) });Expected Behavior
Perhaps the pool's intercept should also receive a signal, to allow aborting such requests, or maybe mockDispatch's handleReply should handle aborted requests
mcollina
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers