cloudflare / cloudflare/workerd
🐛 BUG: Global scope is reused for all worker code, different from cloud environment
- Dominant language
- C++
- Stars
- 8.7k
- Forks
- 739
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 174
Description
### Which Cloudflare product(s) does this pertain to?
Wrangler core
### What version(s) of the tool(s) are you using?
3.6.0
### What version of Node are you using?
18.3.0
### What operating system are you using?
Mac
### Describe the Bug
In the production cloudflare environment the execution environment (global scope) for code is sometimes reused, but only across durable objects of the same class.
So for instance if your wrangler.toml declares two Durable Objects with classes `Chess` and `Checkers`, instances of `Checkers` might sometimes be instantiated in a js context that was previously used by a previous instance of `Checkers`, but they will never be instantiated in the js context previously used by an instance of `Chess`.
Further, I'm pretty sure that in the production environment two instances of a DO can never be "running" at the same time inside an execution context (by running here I mean receiving messages). But I have an open question about that here:
https://discord.com/channels/595317990191398933/773219443911819284/1153898195886293122
In Wrangler, however, all code is run in the same js context (global scope) concurrently.
### Please provide a link to a minimal reproduction
https://github.com/rocicorp/cf-do-js-exec-context
### Please provide any relevant error logs
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.