fix: guard against deleted buffer in vim.schedule callbacks#514
Open
qufeiyan wants to merge 1 commit intostevearc:masterfrom
Open
fix: guard against deleted buffer in vim.schedule callbacks#514qufeiyan wants to merge 1 commit intostevearc:masterfrom
qufeiyan wants to merge 1 commit intostevearc:masterfrom
Conversation
In `system.lua`, the `on_output` callback is wrapped with `vim.schedule_wrap`
and the `on_exit` handler uses `vim.schedule`. Both can fire after the buffer
has been deleted by `reset()` or `dispose()`, causing:
Invalid buffer id: <N>
stack traceback:
...overseer.nvim/lua/overseer/strategy/system.lua:115:
in function 'nvim_buf_line_count'
Add `nvim_buf_is_valid` guards before any buffer operations in deferred
callbacks.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using the
systemstrategy, this error occurs intermittently:Root Cause
The
on_outputcallback is wrapped withvim.schedule_wrap, which defers execution. Between scheduling and execution, the buffer may have been deleted byreset()ordispose()— a TOCTOU race condition. Same issue inon_exit'svim.schedulecallback.Fix
Add
nvim_buf_is_validguards at the top of both deferred callbacks, returning early if the buffer no longer exists.Changes
lua/overseer/strategy/system.lua: two guard clauses (+6 lines)Closes #513
🤖 Generated with Claude Code