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
Weird strong cache for require()
at extension runtime
#84588
Comments
Sounds more scary than it actually is - when loading a file into V8 we produce cached data so that subsequent starts are faster. When a file changed in-between loads (like the config.json-file) its cached data is rejected and these messages are printed. We should make them sound less scary as nothing real has changed |
@jrieken Dig a bit more deeply into this problem, it seems to match the stale cache by mistake, so we can not read the latest change via And it is a serious problem for some extensions that needs to load project configuration files (such as webpack configurations), users may be crazy for these cache. P.S. I workaround this by deleting module cache manually. |
The simplest workaround is to not use |
I have changed the way how messages are logged and that's all I can do here. The caching of module is a node-thing that you get when using |
It's impossible if I want to read IMO, it's not an unimportant log by mistake, and silent failure is the worst solution. Think about this, whether we should patch a custom module loader using |
So how exactly are you patching a JSON-file that has been bundled? |
JSON file is a simple case to reproduce the problem only. As I mentioned above, it's a common scenario:
Users may edit their Even though I workaround this by delete V8 cache manually, I don't think that's a reasonable solution at all, so file the issue for your help. But, if the warning changes to be silent failure, please rollback the codes and just ignore this problem directly, because it will make the thing worse. |
I don't know why you say that, because that's not how it's implemented and not how it works. We create cached data and save that, if the source file for that cached data has changed in the meantime it will be dropped. That fact that |
Actually it is. The problem gone after deleting require cache: function requireUncached(module){
delete require.cache[require.resolve(module)]
return require(module)
} And I respect the new cache mechanism, the key is it breaks these extensions now. Could you please follow the reproduce steps above and have a look at what happened, then from a extension's point of view to think about this ? P.S.More clearly, |
Unsure what you mean - we use cached data since couple of years already, for extensions I believe it's two years, for the rest of VS Code since much longer. Also, it is unrelated to |
Exactly, we can not require new module content if there's require cache in Node.js. But what if I exit and start a new Node.js process, it should require fresh module file, right ? However, at extension runtime:
And it seems these cache introduced several month ago, the strong cache after shut down does not exist on v1.28.0 as far as I know. |
FYI. fef6ca7 |
@jrieken Sadly, you are right. I can not workaround this problem by deleting module require cache. Technically, can we provide a flag to disable this kind of cache for debug purpose (e.g. something like Or a whitelist for 3rd extensions ? Think about that build-in extensions are more controllable and applicable for performance profit. |
That flag exists as |
I also see this problem, but with a different situation. In my ANTLR4 extension I use an JS file which contains code for predicates, used in parsing. For debugging and sentence generation this file must be changable at all times, without restarting vscode. For this I use code to delete the cached module and reload it, whenever a debug session or sentence generation starts. The problem here is similar to what the OP reports: first I see no change, the predicates execute with the old code and after a few seconds the mentioned warnings appear in the console. After that the new code is used instead. The main problem for me is however not the warnings
but the fact that the code is refreshed with a delay, which can confuse the user seriously. In this case I can neither use |
Is this during the time in which you develop the extension or after having shipped the extension? In the former case |
Applies to both, during development and when shipped. I should add that when I talk about debugging, I mean my grammar debugging (with a custom debug adapter), which is also possible with the shipped extension. |
And those grammar files are inside the extension installation location or somewhere else? |
No, the action (predicate) files can be anywhere on a user's disk. Usually I expect them to be in the workspace. |
@mike-lischke That's unfortunate but I am not yet willing to give up fast code loading for extensions (which is why this happens). Would you be able to use the |
Thanks for the suggestion, but how would I unload the code I run with this function, before loading the changed code? A module can much more easily be removed, module variables disappear etc. and module content is isolated. And I believe you can debug code loaded with |
I don't think that you can safely unload arbitrary code, esp not when loaded via require. How would the unloader know what listeners to dispose, what globals the code as set, what APIs with stateful side effects it has used etc (e.g that's the reason vscode needs to restart when uninstalling extensions). Anyways, the VM-module might be able to help you. While it also cannot unload code it allows to load code into a new context, see https://nodejs.org/dist/latest-v12.x/docs/api/vm.html#vm_vm_runinnewcontext_code_sandbox_options, and when loading something again you can load it in yet another new context. That might be helpful for you |
Version: 1.40.0
Commit: 86405ea
Date: 2019-11-06T17:09:34.601Z
Electron: 6.1.2
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Darwin x64 19.0.0
Steps to Reproduce:
Build a simple extension to just read a json file (e.g.
config.json
) opened at workspace usingrequire(fullFilePath)
, and print a specified filed (e.g.version
);Trigger reading via command, and get output value (e.g.
0.0.1
)Edit this json file, change to
0.1.1
and saveTrigger reading via command, and still get the ORIGINAL output value (e.g.
0.0.1
)Nothing changed after restart multi-times, and found these error message at DevTools several times:
Does this issue occur when all extensions are disabled?: Yes
The text was updated successfully, but these errors were encountered: