Skip to content

Race condition results in multiple threads working on server action queue, corrupting state.canonicalUrl #90467

@newportandy

Description

@newportandy

Link to the code that reproduces this issue

https://github.com/newportandy/next-16-action-queue-race-condition

To Reproduce

  1. npm install && npm run build
  2. npm start
  3. Open http://localhost:3000/page-a
  4. While the yellow "Loading..." box is showing (50 fast server actions queuing up), click the blue "Navigate to Page B" button
  5. Wait for Page B to render, you'll see what the current state.canonicalUrl is set to (it alternates as the two thread fight over it)
  6. Depending on which thread ran last, clicking "Save" on Page B will either work as expected or redirect you incorrectly to /page-a

Current vs. Expected behavior

Current behaviour:
Depending on which thread ran last, submitting a server action on page B will either correctly stay on page B, or it will redirect to page A.

Expected behaviour:
The server action doesn't redirect to page A arbitrarily.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:11:08 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8122
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.12.0
  npm: 10.9.0
  Yarn: 1.22.22
  pnpm: 10.8.0
Relevant Packages:
  next: 16.2.0-canary.59 // Latest available version is detected (16.2.0-canary.59).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Dynamic Routes, Server Actions

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local), Other (Deployed)

Additional context

This issue seems to first appear in 16.0.0, testing with 15.5.12 doesn't surface the same state corruption issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions