wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

When closing tab or application, current focus window in tmux is closed on mac

Open umlx5h opened this issue 2 years ago • 9 comments

What Operating System(s) are you seeing this problem on?

macOS

Which Wayland compositor or X11 Window manager(s) are you using?

No response

WezTerm version

20230911-075810-70931f58

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

Thank you for developing this useful terminal application.

I am using wezterm on WSL2 and Mac, but I have confirmed that it behaves strangely when using tmux only in the Mac environment.

When I am attaching to a tmux session on wezterm, if I close the wezterm tab or quit the application, the tmux window that is currently in focus is closed for some reason. If multiple windows are launched in the current session of tmux, only the window with focus is closed by itself.

It appears that EOF(CTRL+D) is sent on quitting application. If you are SSHing in an active window, then disconnects session.

I tried to find the related config and changed exit_behavior to 'Hold', but the behavior did not change. https://wezfurlong.org/wezterm/config/lua/config/exit_behavior.html

Is it possible to disable this EOF being sent behavior? Since I use tmux for session maintenance purposes, this behavior seemed unnatural to me.

I migrated from iTerm2 and iTerm2 did not have this problem. This behavior does not occur in WSL2. The version of tmux on mac is 3.3A and WSL2 is 3.2A.

To Reproduce

No response

Configuration

config.window_close_confirmation = 'NeverPrompt'

Expected Behavior

No response

Logs

No response

Anything else?

No response

umlx5h avatar Sep 20 '23 08:09 umlx5h

Ah, I'd forgotten about this logic:

https://github.com/wez/wezterm/blob/4adbe89cb34885c24ed7663a6272dacfd6b6c415/pty/src/unix.rs#L394-L403

it was added in e6421d1b725715abe0463ea9040909de78c56563 to resolve:

  • https://github.com/wez/wezterm/discussions/2392
  • https://github.com/wez/wezterm/issues/1396

I tried to reproduce the behavior you described:

  • Open a new tab
  • Run tmux
  • type in echo hello and press enter so that I can tell that this session is the same one later
  • Close the tab by clicking the X button
  • In a new tab, run tmux attach. I see the echo hello text I entered before.

I tried this on both linux and macos with the behavior being the same. This behavior is what I expect; the tmux session is there when I come back to it.

What's different about your setup?

wez avatar Sep 21 '23 22:09 wez

I tried to reproduce the behavior you described:

I reproduced this, but If I closed the application by pressing CMD+Q instead of tab, then tmux session is gone. (If current tmux session has multiple window or pane, current focus window/pane is closed.)

I thought it was a Wezterm specific issue since it does not occur in Iterm2, mac default terminal. I use zsh and tmux as well on WSL2 and Mac, but I can only reproduce it on Mac.

I disabled all tmux and zsh configuration files and checked the behavior, but there was no change in behavior.

zsh: 5.9
tmux: 3.3a

umlx5h avatar Sep 26 '23 04:09 umlx5h

Please share the exact steps you take to trigger the behavior you described

wez avatar Sep 26 '23 05:09 wez

I'm sorry. This is the exact step.

preparation

# disable for default settings
rm -rf ~/.tmux.conf ~/.zshrc ~/.wezterm

pattern 1: when closing wezterm application

1. Open wezterm
2. Create first tmux session and enter
$ tmux
3. Exit application by pressing CMD+Q (confirm popup yes)
4. tmux session is gone (bug)
$ tmux ls
no server running on ...

pattern 2: when closing wezterm tab

1. Open wezterm
2. Create first tmux session and enter
$ tmux
3. Open another wezterm tab by pressing CMD+T
4. Create second tmux session and enter
$ tmux
5. Create another pane by pressing C-b %
6. Close second wezterm tab by pressing X
7. Create wezterm tab by pressing CMD+T
8. Attach previous tmux session
$ tmux attach -t 1
9. **Randomly** right pane is closed (bug)

I have checked many times and if I exit the application itself (1 pattern), the bug is definitely reproduced.

'pattern 2' is reproduced randomly for some reason. (I repeat 5-9 steps) I have tried 10 times and 5 times the bug reproduced.

Is it possible to reproduce it randomly in your environment as well?

umlx5h avatar Sep 26 '23 06:09 umlx5h

#4562 and this might be related? although mine is a linux platform. @umlx5h

uncomfyhalomacro avatar Nov 13 '23 05:11 uncomfyhalomacro

It happens for me as well (fish shell). Closing tab / application closes my focused tmux pane.

orellazri avatar Feb 22 '24 18:02 orellazri

It happens for me as well (fish shell). Closing tab / application closes my focused tmux pane.

https://build.opensuse.org/package/view_file/X11:terminals/wezterm/do-not-send-eof-when-closing-application.patch?expand=1 i made a patch so it doesn't do that.

uncomfyhalomacro avatar Feb 24 '24 09:02 uncomfyhalomacro

Same again here. I noticed though that this only happens for tmux windows that contain a shell. If they're running an ncurses application such as mc or htop, then everything is fine, the tmux window is not closed. The ^D / EOT is only being responded to by the shell, which exits (and closes the tmux window).

Here is a work-around, of sorts. Add this line to your tmux.conf:

bind-key -n C-d detach

This will bind Ctrl-D (without a tmux prefix) to the tmux detach command. When tmux intercepts the ^D / EOT from WezTerm, it will detach the session, keeping the currently focused window open, even if it's a shell.


Of course, this setting means you cannot send ^D to an application within tmux.

I think the correct fix would be to add some kind of option or switch in wezterm for the fix for portable_pty


If you need to be able to send an actual ^D / EOT to some application, then a work-around to the work-around is to add another setting to tmux.conf:

bind C-d send-keys "^D"

So now, if EOT is received, then tmux will detach

But, if you press prefix Ctrl-D, tmux will send EOT (which in a shell, will exit the shell and close the window).

sinewalker avatar Oct 11 '24 07:10 sinewalker

I'm having this same issue - is there any progress on a fix?

itsvyle avatar May 21 '25 11:05 itsvyle

Same issue here. Closing wezterm while tmux is open will kill one of the tmux windows.

radutomy avatar Nov 01 '25 05:11 radutomy