-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Web workers appear to reuse same module cache #16503
Comments
I believe this behavior matches what browsers do - once you fetch the source once it won't be fetched again in the same session (or until cache expires). If you really want to reload the source you can add a query param that will cache-bust, something like: |
I'm gonna close this issue for now, I suggest to use the above solution if you really need to reload sources in-process. |
I dont think that adding a date time is a valid solution because in trying this it still loads the cached module. the only way I can seem to bust the cache is by starting a new process or by doing this: Deno[Deno.internal].core.ops.op_create_worker({ hasSourceCode: true, name: "hello", sourceCode: await Deno.readTextFile("./my-script.ts"), permissions: {}, workerType: "module", specifier: "file:///dev/null"}) ...which is a nightmare because I can't easily post messages to it or anything because i haven't bothered to read how passed messages get serialized and also probably shouldn't be possible because type === "module" && hasSourceCode === true??? |
@bartlomieju Looking deeper I seem to have found the culprit is the way Deno is calculating module specifiers. see my patch here: https://github.com/denoland/deno/pull/17755/files |
mmmm no that doesn't seem right..... 😮💨 |
@bartlomieju , does this means that Deno's web worker will keep the module in memory even after it's terminated, and won't free up the memory until the main session is ended? |
This appears to be a regression (was previously reported in #6116). My understanding is that each web worker is supposed to its own separate module cache that is separate from the one used for the main thread and those used for other workers.
Web Worker References
Environment
OS: Windows 11 Home Version 22H2
Observed in Deno v1.27.0
Steps to reproduce
I initially observed this in a more complicated example and provide that context if desired, but for simplicity sake I reusing the steps from #6116 as I believe they illustrate the same issue and is much simpler.
Create a file
script.ts
with the contentconsole.log('hello')
.Create another file
main.ts
with the following content:Run this command:
deno run --allow-read main.ts
.Modify the content of
script.ts
toconsole.log('bye')
and save it.Expected behavior
The subsequent log of
deno run --allow-read main.ts
should bebye
.Observed behavior
After step 4, the subsequent log of
deno run --allow-read main.ts
is stillhello
.Notes
Testing with JS files yielded the same result. I also tried using
self.close
in the worker rather thanworker.terminate
and again got the same result.The text was updated successfully, but these errors were encountered: