Skip to content
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

fix(#2906): resource leak on populate children #2907

Merged
merged 2 commits into from
Sep 14, 2024

Conversation

ianhomer
Copy link
Collaborator

@ianhomer ianhomer commented Sep 13, 2024

FIx for #2906

It looks like there are some situations where the explorer tries to populate a node when it is already populated. This leads to a situation in the code where the filter reason is none, however the node has already been loaded. This in turn leads to an attempt to record the hidden stats for the reason. Since the reason however is none and the hidden_stats object has understandably not been initialised to capture stats for reason none, the following exception is thrown

Error executing vim.schedule lua callback: ...r/start/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:69: attempt to perform
 arithmetic on a nil value
stack traceback:
        ...r/start/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:69: in function 'populate_children'

The fix changes the logic so that no attempt to record hidden stats are made and the node is not reloaded. I'm assuming here that the node has been loaded OK if the path is in the nodes_by_path object. I welcome any feedback on whether that is a good assumption.

@ianhomer ianhomer changed the title Don't collect reason statistics for reason none fix: don't collect reason statistics for reason none Sep 13, 2024
@ianhomer ianhomer changed the title fix: don't collect reason statistics for reason none fix(#2906) : don't collect reason statistics for reason none Sep 13, 2024
@ianhomer ianhomer changed the title fix(#2906) : don't collect reason statistics for reason none fix(#2906): don't collect reason statistics for reason none Sep 13, 2024
Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love your work @ianhomer
FYI as a trusted member of the nvim-tree community you can push branches etc. to the main repo.

We're back to the pre-filter logic - not populating when nodes_by_path contains: https://github.com/nvim-tree/nvim-tree.lua/pull/2856/files#diff-1b05da4f503ff1df76cfeb7ef723f260d51acd287b0486f9de0ed61b2eeaa042L21

@alex-courtis
Copy link
Member

I'm buggered if I can replicate the telescope example, however this looks correct and might resolve #2902

@alex-courtis alex-courtis changed the title fix(#2906): don't collect reason statistics for reason none fix(#2906): resource leak on populate children Sep 14, 2024
@alex-courtis alex-courtis merged commit a4dd5ad into nvim-tree:master Sep 14, 2024
5 checks passed
@ianhomer
Copy link
Collaborator Author

I'm buggered if I can replicate the telescope example, however this looks correct and might resolve #2902

It took me a while to isolate the steps to trip this. I do have a set of repositories (that I can't share) and it would happen every time I did the steps to reproduce. I ended up deleting stuff to find the minimal set to get the error, but may be I isolated steps for my env only. It feels like a race condition and perhaps it's also dependent on hardware performance. I just tested the steps to reproduce again and I do still get the error on the commit before this fix merged.

I've also verified that the error doesn't happen for me on the latest release (after this fix merged), so looks good to me.

@alex-courtis
Copy link
Member

It feels like a race condition and perhaps it's also dependent on hardware performance. I just tested the steps to reproduce again and I do still get the error on the commit before this fix merged.

Ah... you might be referring to this shameful hack:

local event_running = false

I've also verified that the error doesn't happen for me on the latest release (after this fix merged), so looks good to me.

Sounds like we've fixed the symptom at least. Let's monitor.

@alex-courtis
Copy link
Member

I'm hoping we can get rid of that ineffective lock during https://github.com/orgs/nvim-tree/projects/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants