Skip to content

Infinite recursion causing 100% CPU when calling :PrevimOpen on macOS Apple Silicon #171

@santoshmano

Description

@santoshmano

Environment

  • OS: macOS 15.6 (Apple Silicon)
  • Vim: 9.1.754 (system vim)
  • Plugins: previm + open-browser.vim (latest from vim-plug)
  • Config: Default plugin configuration, no customization

Problem Description

Problem

Vim enters an infinite loop at 100% CPU when running :PrevimOpen. The browser actually opens and displays the preview, but then vim becomes unresponsive and must be killed with kill -9.

When I checked with top, vim was using 100% of a single CPU core and showed state R+ (actively running, not blocked). It ran like this for 45+ minutes before I killed it.

I caught this happening once and collected debugging data before killing the process. The hang isn't consistently reproducible.


Reproduction Steps

Reproduction

vim --clean document.md

In Vim:

:set rtp+=~/.vim/plugged/open-browser.vim
:set rtp+=~/.vim/plugged/previm
:PrevimOpen

The file I was editing had some mermaid diagrams in it, around 36KB. Not sure if that's relevant.

Note: This only happened once and I haven't been able to reproduce it again, which makes me think it might be a race condition or timing issue.


Debugging Evidence

Debug Info

When I ran ps aux, vim showed:

PID   %CPU   TIME      STATE
23634 98.9   48:20.87  R+

So it was spinning on CPU for nearly 48 minutes straight, not waiting on I/O or anything.

I ran sample on the hung process and found it was stuck in an infinite recursion. The same address (0x104fe5304) appears multiple times in the call stack:

+ ???  (in vim)  load address 0x104f9c000 + 0x49304  [0x104fe5304]
  + ???  (in vim)  0xd391c
    + ???  (in vim)  0xcc5f4
      + ???  (in vim)  0xccd94
        + ???  (in vim)  0xce178
          + ???  (in vim)  0x49304  [0x104fe5304]  ← back to same address
            + ???  (in vim)  0x3ba38
              + ???  (in vim)  0x49304  [0x104fe5304]  ← and again

The process used 100% CPU continuously. lsof showed previm had created temp files successfully, so the hang happened during the browser launch phase.

Temp directory had these files:

-rw-r--r--  1 user  staff  36171  3.1.1.md
-rw-r--r--  1 user  staff  36171  3.1.2.md
-rw-r--r--  1 user  staff  36171  4.1.1.md
-rw-r--r--  1 user  staff  36171  4.1.2.md

I tried to attach with lldb but macOS security prevented it.


What I Think Is Happening

Based on the stack trace, it looks like previm generates the files fine, then calls open-browser to launch the browser, and the browser does open successfully. But after that, vim gets stuck in an infinite recursion and never returns control to the user.

Not sure if it's a vim bug or an issue with how open-browser calls the system open command, but thought the stack trace might help narrow it down.


Additional Info

  • open https://google.com works fine from terminal
  • Can't reproduce the hang consistently (only happened once)
  • When it did hang, it ran for 45+ minutes before I killed it

Let me know if you need more details or if I can test anything!

Thanks for building such cool plugins! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions