diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2023-11-14 17:02:57 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-14 17:02:57 -0600 |
commit | ba58c6f8a44c9c37e97fce1d802dc5b5defceb3d (patch) | |
tree | d8692391000b997bad511f5391e4dc727fc3ad9a | |
parent | c37f7bdba5069eb989c3374c660b540e7539f874 (diff) | |
download | rneovim-ba58c6f8a44c9c37e97fce1d802dc5b5defceb3d.tar.gz rneovim-ba58c6f8a44c9c37e97fce1d802dc5b5defceb3d.tar.bz2 rneovim-ba58c6f8a44c9c37e97fce1d802dc5b5defceb3d.zip |
fix: only attempt to close timer if not already closing (#26047)
This fixes an error that can occur in certain pathological cases when
the autocommand fires at just the right time such that it attempts to
close the timer after the timer has already exited, but before the
scheduled callback has fired.
We now let the timer continue to run even when the autocommand deletes
itself to avoid having to repeat the cleanup code multiple times. There
is no harm in letting the timer execute if the autocommand does not
exist, as the pcall will catch the error.
-rw-r--r-- | runtime/lua/vim/_defaults.lua | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 0d7b4f1884..870603c9f3 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -254,8 +254,6 @@ do callback = function(args) if vim.api.nvim_get_option_info2('background', {}).was_set then -- Don't do anything if 'background' is already set - timer:stop() - timer:close() return true end @@ -274,9 +272,6 @@ do end end - timer:stop() - timer:close() - return true end end, @@ -290,7 +285,10 @@ do -- Suppress error if autocommand has already been deleted pcall(vim.api.nvim_del_autocmd, id) end) - timer:close() + + if not timer:is_closing() then + timer:close() + end end) end end |