-
-
Notifications
You must be signed in to change notification settings - Fork 835
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
Reinstalling language parser fails on Windows when a file handle to the old parser exists #6494
Comments
Sorry, but this is too niche to optimize for. (And we can't and won't work around issues with lazy.) You can test the |
Okay, but just for clarification: it's not got anything to do with lazy. I mentioned lazy only as an example of one way it gets triggered. I also called the language parsers 'plugins', which may have contributed to some confusion, so I edited that. I've also discovered a simpler set of reproduction steps:
Even though NeoVim has no open buffers that need the language parser by step 4, the file handle remains open and blocks the reinstall. I have to close NeoVim and reopen it for the reinstall to succeed. If this is too niche to fix, so be it. I just want to make sure I'm clearly and accurately documenting this problem. Thank you for your time. |
That's not something that can be fixed here, though -- the parser use is handled by Neovim itself (and I don't know if tree-sitter itself provides a function for releasing the parser file). We could handle installation failures on Windows better, but
Again, can you test the |
Ahh, thanks for letting me know. I feel a bit sheepish to admit I didn't realize |
Yes, nightly is required; I thought the Readme made that clear. I'm not sure there's anything we can do on the neovim side either, to be honest. |
The problem that @FlippingBinary is mentioning is that we don't really care about garbage collecting parsers. We're well aware that we're leaking the parsers instead of tracking their usage in buffers and then properly |
@theHamsta Thank you for that info! I found where Neovim calls Obviously, Microsoft is not going to change their architectural decision to enforce exclusive access on loaded dlls any time soon, and nobody wants to impact performance by eliminating caching. However, I may have found a workaround that can be automated in Even though the language parser cannot be replaced on disk while it is loaded, it can be moved. I confirmed this by changing into the directory and calling So here is what I'm proposing: While reinstalling a language parser on Windows, right before moving the new parser into place, rename the old parser to something that can be easily matched with a wildcard, like Then If this approach is acceptable, I'd be willing to write up a pull request. |
Sorry, but that's still too much for a situation we don't see as central. As I said, |
I'm loving this conversation because I'm learning so much and my proposal is evolving along the way. @clason My perspective is long-term. I'm willing to contribute a PR to Here is my updated proposal:
Similarly, during uninstallation (for completeness):
That would be super simple. In many cases (and only on Windows), it would simply reverse the sequence of events with one additional step of moving the file and another informing the user, and I am offering to write the code myself. Would you please reopen this issue and entertain a PR? |
Describe the bug
Treesitter seems to open an exclusive file handle to plugins that are in use, and doesn't release them during reinstallation.
To Reproduce
:TSInstall <language>
, e.g.:TSInstall rust
.y
(this bug only occurs on reinstallation, not initial installation)Expected behavior
The parser reinstalls successfully.
Output of
:checkhealth nvim-treesitter
Output of
nvim --version
Additional context
I'm using LazyVim, which provides
lazy.nvim
andnvim-treesitter
.After failing to update a parser, the output of
:messages
shows this:When I open another terminal and attempt the command manually:
The error message appears like this:
The obvious workaround is to run
:TSUpdate
or:TSInstall <language>
before any affected parsers are loaded. However, that won't prevent the error from occurring, and the error message doesn't guide the user to that workaround.I most frequently see this error when I open a new instance of NeoVim and see that updated plugins are available, one of which happens to be
nvim-treesitter
. If I update it, Treesitter may then need to rebuild some of its parsers. The markdown parser always seems to be open, even if there is only one instance of NeoVim with no files open (just the initial start screen withlazy.nvim
open). So I see this error often.Below, I identify four potential solutions:
Access is denied
and print advice to the user suggesting they close every instance of NeoVim and executenvim -c "TSUpdate"
in the terminal. This would help new users avoid the time sink of figuring out which repository is relevant, then searching through open issues and following random troubleshooting advice.<language>.so.new
when unable to replace the existing parser and check for similarly named files on startup to see if they can be moved to<language>.so
at that time. This would act as a kind of two-stage installer where reinstalled/upgraded parsers do not immediately take effect when the old version was in use during installation.<language>.so.lock
and be used to tell other instances ofnvim-treesitter
that they need to close any file handle of the affected parser temporarily. The updater could create the file before beginning to build the parser so other instances ofnvim-treesitter
have time to notice before the new version is actually installed. Then the updater could try to install the updated parser for a limited amount of time with the expectation that the other instances will close the parser when they see the flag, even if they didn't get a chance to before the updater was ready. Meanwhile, the other instances that need the parser can watch for the flag to disappear, indicating it is safe to reopen the new parser.Edit: Updated some references to 'plugin' when 'parser' was more appropriate.
The text was updated successfully, but these errors were encountered: