[PR #14160] Fix a deadlock during ConPTY shutdown #29974

Closed
opened 2026-01-31 09:37:55 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/14160

State: closed
Merged: Yes


Problem:

  • Calling RundownAndExit tries to flush out the last frame from VtEngine
  • VtEngine indirectly calls RundownAndExit if the pipe is gone via VtIo
  • RundownAndExit is called by other parts of OpenConsole
  • RundownAndExit must be [[noreturn]] for most parts of OpenConsole
  • VtIo itself has a mutex ensuring orderly shutdown
  • In short, doing a thread safe orderly shutdown requires us to hold both,
    a lock in RundownAndExit and VtIo at the same time, but while other parts
    need a blocking RundownAndExit, VtIo needs a non-blocking one
  • Refactoring the code to use optionally non-blocking RundownAndExit
    requires refactoring and might prove to be just as buggy

Solution:

  • Simply don't call RundownAndExit in VtEngine at all
  • In case the write pipe breaks:
    • VtEngine will close the handle
    • The client should notice that their read pipe is broken and
      close their write pipe sooner or later
    • Once we notice that our read pipe is broken, we call RundownAndExit
    • RundownAndExit might call back into VtEngine but
      without a pipe it won't do anything
  • In case the read pipe breaks or any other part calls RundownAndExit:
    • We call RundownAndExit
    • RundownAndExit might call back into VtEngine and depending on whether
      the write pipe is broken or not it will simply write into it or ignore it

Closes #14132
Pretty sure this also applies to #1810

Validation Steps Performed

  • Open 5 tabs and run MSYS2's bash --login in each of them
  • Enter-VsDevShell in another tab
  • Close window
  • 5 tab processes are killed instantly, 1 after ~3s
  • Replace conhost with OpenConsole via sfpcopy
  • Launch Dozens of Git Bash tabs in VS Code
  • Close them randomly
  • Remaining ones still work, processes are gone
**Original Pull Request:** https://github.com/microsoft/terminal/pull/14160 **State:** closed **Merged:** Yes --- Problem: * Calling `RundownAndExit` tries to flush out the last frame from `VtEngine` * `VtEngine` indirectly calls `RundownAndExit` if the pipe is gone via `VtIo` * `RundownAndExit` is called by other parts of OpenConsole * `RundownAndExit` must be `[[noreturn]]` for most parts of OpenConsole * `VtIo` itself has a mutex ensuring orderly shutdown * In short, doing a thread safe orderly shutdown requires us to hold both, a lock in `RundownAndExit` and `VtIo` at the same time, but while other parts need a blocking `RundownAndExit`, `VtIo` needs a non-blocking one * Refactoring the code to use optionally non-blocking `RundownAndExit` requires refactoring and might prove to be just as buggy Solution: * Simply don't call `RundownAndExit` in `VtEngine` at all * In case the write pipe breaks: * `VtEngine` will close the handle * The client should notice that their read pipe is broken and close their write pipe sooner or later * Once we notice that our read pipe is broken, we call `RundownAndExit` * `RundownAndExit` might call back into `VtEngine` but without a pipe it won't do anything * In case the read pipe breaks or any other part calls `RundownAndExit`: * We call `RundownAndExit` * `RundownAndExit` might call back into `VtEngine` and depending on whether the write pipe is broken or not it will simply write into it or ignore it Closes #14132 Pretty sure this also applies to #1810 ## Validation Steps Performed * Open 5 tabs and run MSYS2's `bash --login` in each of them * `Enter-VsDevShell` in another tab * Close window * 5 tab processes are killed instantly, 1 after ~3s ✅ * Replace conhost with OpenConsole via sfpcopy * Launch Dozens of Git Bash tabs in VS Code * Close them randomly * Remaining ones still work, processes are gone ✅
claunia added the pull-request label 2026-01-31 09:37:55 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#29974