Skip to content

MSW sometimes still handles requests after worker was stopped #2597

@diego-aquino

Description

@diego-aquino

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 20 or higher

Browsers

Chromium (Chrome, Brave, etc.)

Reproduction repository

https://github.com/diego-aquino/msw-worker-stop-bypass-issue

Reproduction steps

  1. pnpm install
  2. pnpm test

Current behavior

Starting in msw@2.11.2, I found out that workers sometimes handle requests even after worker.stop() is called.

In the reproduction repository, this expect sometimes passes, sometimes fails.

https://github.com/diego-aquino/msw-worker-stop-bypass-issue/blob/main/example.browser.test.ts#L20-L25

  worker.stop();

  // This expect sometimes passes, sometimes fails.
  await expect(async () => {
    await fetch(`${baseURL}/users`);
  }).rejects.toThrowError(TypeError);

I've recorded a video demonstrating the flakiness, in case it's difficult to reproduce:

recording-2025-09-27_16.50.19.mp4

From my tests, I did not see this issue happening with server.close(), neither with worker.stop() and server.close() before 2.11.2 (I tested 2.11.1).

Expected behavior

I expected all requests made after worker.stop() was called to not be handled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds:triageIssues that have not been investigated yet.scope:browserRelated to MSW running in a browser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions