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

ModeChanged event is constantly triggered till 100% cpu uses with scheduled callback function #22263

Closed
shadmansaleh opened this issue Feb 14, 2023 · 2 comments · Fixed by #23288
Labels
bug issues reporting wrong behavior event-loop events events, autocommands

Comments

@shadmansaleh
Copy link
Contributor

Describe the bug

If callback function of a ModeChanged autocmd schedules some operations with vim.schedule ModeChaged event constantly gets triggered switching between mods 'n' and 'no' when user switches to operator pending mode. As a result the callback gets called again and again until nvim saturates the cpu.
,

Steps to reproduce

file minimal_init.lua

local s = 0
local t = 0
vim.api.nvim_create_autocmd('ModeChanged', {
  callback = function ()
    s = s + 1
    print('callback scheduled', s)
    vim.schedule(function ()
      t = t + 1
      print('callback triggered', t)
    end)
  end,
})

Open neovim with the minimal config

nvim --clean -u minimal_init.lua

go into operator pending mode by pressing d for example.

Expected behavior

The ModeChanged event should get triggerd only once and the callback should be ran only once.

Neovim version (nvim -v)

0.9.0 commit 264fb69

Vim (not Nvim) behaves the same?

no. vim doesn't really have vim.schedule

Operating system/version

Arch Linux

Terminal name/version

kitty

$TERM environment variable

xterm-kitty

Installation

build from repo

@shadmansaleh shadmansaleh added the bug issues reporting wrong behavior label Feb 14, 2023
@clason clason added event-loop events events, autocommands labels Feb 14, 2023
shadmansaleh added a commit to nvim-lualine/lualine.nvim that referenced this issue Feb 14, 2023
Mitigation for #967

This happens primarily because of
neovim/neovim#22263

To prevent this from affecting lualine. Mode changed event
for op-pending mode no longer gets scheduled.

As a side effect lualine no longer properly refreshes upon switching
to op-pending mode.
@akai54
Copy link

akai54 commented Feb 20, 2023

Hi,
I would really like to work on this issue, but I don't know really know where to start, neither how,
if anyone can point at least the files I should be checking for this, it would be awesome.

@MunifTanjim
Copy link
Contributor

Relevant Codes:

craigmac pushed a commit to craigmac/lualine.nvim that referenced this issue May 15, 2024
Mitigation for nvim-lualine#967

This happens primarily because of
neovim/neovim#22263

To prevent this from affecting lualine. Mode changed event
for op-pending mode no longer gets scheduled.

As a side effect lualine no longer properly refreshes upon switching
to op-pending mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior event-loop events events, autocommands
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants