nohup process terminates when terminal disconnects from ssh session #22352

Open
opened 2026-01-31 08:10:39 +00:00 by claunia · 5 comments
Owner

Originally created by @siddhsql on GitHub (Oct 5, 2024).

Windows Terminal version

1.20.11781.0

Windows build number

10.0.22631.4169

Other Software

No response

Steps to reproduce

  1. ssh to a remote machine from the Windows terminal
  2. run a program (e.g., a node process that spins up a server listening to connections) like nohup npm run &

leave terminal connected. after some period of inactivity (could be few hours) terminal will disconnect (broken pipe) as machine could go to sleep etc.

When this happens the program you started on the remote machine also terminates.

Expected Behavior

program you started on the remote machine should keep running.

Actual Behavior

program you started on the remote machine terminates. Note this does not happen if you exit from the ssh session by typing the exit command vs. leaving the terminal connected and it disconnects due to inactivity. if it helps, on Mac (with iTerm), the problem does not happen when leaving the terminal connected and it disconnects due to inactivity

Originally created by @siddhsql on GitHub (Oct 5, 2024). ### Windows Terminal version 1.20.11781.0 ### Windows build number 10.0.22631.4169 ### Other Software _No response_ ### Steps to reproduce 1. ssh to a remote machine from the Windows terminal 2. run a program (e.g., a node process that spins up a server listening to connections) like `nohup npm run &` leave terminal connected. after some period of inactivity (could be few hours) terminal will disconnect (broken pipe) as machine could go to sleep etc. When this happens the program you started on the remote machine also terminates. ### Expected Behavior program you started on the remote machine should keep running. ### Actual Behavior program you started on the remote machine terminates. _Note this does not happen if you exit from the ssh session by typing the `exit` command vs. leaving the terminal connected and it disconnects due to inactivity_. if it helps, on Mac (with iTerm), the problem does not happen when leaving the terminal connected and it disconnects due to inactivity
claunia added the Issue-BugNeeds-Tag-FixNeeds-ReproProduct-Terminal labels 2026-01-31 08:10:39 +00:00
Author
Owner

@DHowett commented on GitHub (Oct 5, 2024):

Are you using ssh from within WSL, or the native Windows build of ssh?

@DHowett commented on GitHub (Oct 5, 2024): Are you using ssh from within WSL, or the native Windows build of ssh?
Author
Owner

@siddhsql commented on GitHub (Oct 5, 2024):

I have tried both.

  1. ssh from Windows (no WSL)
  2. ssh from WSL using /usr/bin/ssh
@siddhsql commented on GitHub (Oct 5, 2024): I have tried both. 1. ssh from Windows (no WSL) 2. ssh from WSL using `/usr/bin/ssh`
Author
Owner

@lhecker commented on GitHub (Oct 7, 2024):

I just tried this with my own Linux server from Windows 11 24H2. After disconnecting the network, the process kept running in the background while SSH had exited.

What I suspect is happening is that your server is receiving a signal other than SIGHUP. nohup only catches that one signal and any other signal will still cause node to exit.

As an immediate workaround, I'd suggest either changing your command to npm run &; disown or to use a multiplexer like tmux or zellij. With tmux for instance, you first launch it by running tmux, then you execute your command npm run. No matter what happens now, that tmux and npm instance will keep running forever. You can explicitly detach from it by pressing Ctrl+B, D. You can reattach again by running tmux attach. zellij works similar but is a lot more beginner friendly.

@lhecker commented on GitHub (Oct 7, 2024): I just tried this with my own Linux server from Windows 11 24H2. After disconnecting the network, the process kept running in the background while SSH had exited. What I suspect is happening is that your server is receiving a signal other than SIGHUP. `nohup` only catches that one signal and any other signal will still cause `node` to exit. As an immediate workaround, I'd suggest either changing your command to `npm run &; disown` or to use a multiplexer like `tmux` or `zellij`. With `tmux` for instance, you first launch it by running `tmux`, then you execute your command `npm run`. No matter what happens now, that `tmux` and `npm` instance will keep running forever. You can explicitly detach from it by pressing `Ctrl+B, D`. You can reattach again by running `tmux attach`. `zellij` works similar but is a lot more beginner friendly.
Author
Owner

@siddhsql commented on GitHub (Oct 7, 2024):

Thanks Leonard. re: this:

After disconnecting the network, the process kept running in the background while SSH had exited.

could you be specific how you disconnected from the network? If I disconnect by explicitly exiting from the ssh session using the exit command, the process does keep running. I encounter the issue when the session terminates/disconnects because of prolonged inactivity (Broken Pipe). Did you repro that?

@siddhsql commented on GitHub (Oct 7, 2024): Thanks Leonard. re: this: >After disconnecting the network, the process kept running in the background while SSH had exited. could you be specific how you disconnected from the network? If I disconnect by explicitly exiting from the ssh session using the `exit` command, the process does keep running. I encounter the issue when the session terminates/disconnects because of prolonged inactivity (Broken Pipe). Did you repro that?
Author
Owner

@lhecker commented on GitHub (Oct 9, 2024):

I disabled the network adapter. I hoped that this would be similar to what you experienced.

@lhecker commented on GitHub (Oct 9, 2024): I disabled the network adapter. I hoped that this would be similar to what you experienced.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22352