Skip to content

MockAgent delayed response with AbortSignalΒ #4693

@atlowChemi

Description

@atlowChemi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions