Skip to content

ModuleRunner - Sharing concurrentModuleNodePromises across invocations is not compatible with Cloudflare Workers runtime #20283

Open
@jamesopstad

Description

@jamesopstad

Describe the bug

The caching of concurrentModuleNodePromises implemented in the ModuleRunner is not compatible with the Cloudflare Workers runtime.

private async cachedModule(
url: string,
importer?: string,
): Promise<EvaluatedModuleNode> {
let cached = this.concurrentModuleNodePromises.get(url)
if (!cached) {
const cachedModule = this.evaluatedModules.getModuleByUrl(url)
cached = this.getModuleInformation(url, importer, cachedModule).finally(
() => {
this.concurrentModuleNodePromises.delete(url)
},
)
this.concurrentModuleNodePromises.set(url, cached)
} else {
this.debug?.('[module runner] using cached module info for', url)
}
return cached
}

This is because it violates a constraint of the Workers runtime that I/O objects can't be shared between invocations (https://developers.cloudflare.com/workers/observability/errors/#cannot-perform-io-on-behalf-of-a-different-request). We have only encountered this recently when debugging cloudflare/workers-sdk#9518 but it seems to be a common issue for users building larger apps.

It would be good to understand if this promise caching is just an optimisation or if it serves to prevent invalid states. If it's just an optimisation then the simplest option might be to offer a way to opt out.

Reproduction

https://github.com/SlexAxton/cf-bug-repro-9518

Steps to reproduce

cloudflare/workers-sdk#9518 (comment)

System Info

System:
    OS: macOS 15.5
    CPU: (12) arm64 Apple M3 Pro
    Memory: 4.12 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.2.0 - ~/.nvm/versions/node/v24.2.0/bin/node
    npm: 11.3.0 - ~/.nvm/versions/node/v24.2.0/bin/npm
    pnpm: 10.12.1 - ~/.nvm/versions/node/v24.2.0/bin/pnpm
  Browsers:
    Chrome: 137.0.7151.120
    Safari: 18.5

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-downstream-blockerBlocking the downstream ecosystem to work properly (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions