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
Bug Description
MockAgentwith delayed responses handle the reply even for aborted controllers, possibly causing anuncaughtExceptionerror when an AbortSignal aborted the request.I noticed this when trying to add the
decompressinterceptor, which has an assertion ofassert(!this.#onErrorCalled)inonResponseStart, which in this case is being called after the controller was aborted.Reproducible By
Expected Behavior
Perhaps the pool's
interceptshould also receive a signal, to allow aborting such requests, or maybemockDispatch'shandleReplyshould handle aborted requests