wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
17.72k stars 793 forks source link

Error after manually closing last tab on ssh domain #4161

Open dominz88 opened 1 year ago

dominz88 commented 1 year ago

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

Linux Wayland

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

Gnome-shell

WezTerm version

20230712-072601-f4abf8fd

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

Hello,

I encounter this weird error while using hotkeys on gnome. In gnome (at least in ubuntu), you can open/toggle an application that is in the dock using Win+N (where N is the position of the app in the dock).

My goal is to always connect to my default ssh domain when starting wezterm and open/toggle wezterm while using a hotkey. This is to emulate the behavior of a drop-down-terminal (like Guake) + tmux over ssh for persistent shells on my remote machine.

It works fine in general, but if I close the last remaining tab manually or with Ctrl-D, I get the message bellow when opening westerm and i'm forced to open a new tab and then close the tab that contains de error message.

Process "/bin/zsh" in domain "local" didn't exit cleanly
Exited with code 1.
This message is shown because exit_behavior="CloseOnCleanExit"No such file or directory (os error 2)

Thanks for your help

To Reproduce

Configuration

local wezterm = require 'wezterm'
local config = {}
config.default_domain =  'sysadmin'
config.ssh_domains = {
  {
    name = 'sysadmin',
    remote_address = 'sysadmin',
    username = 'ubuntu',
  },
}

config.keys = {
  {
    key = 'F11',
    --    mods = 'SHIFT|CTRL',
    action = wezterm.action.ToggleFullScreen,
  },
  {
    key = 'F2',
    mods = 'CTRL',
    action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' },
  },
  {
    key = 'F2',
    mods = 'SHIFT',
    action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' },
  },
}

return config

Expected Behavior

Instead of showing a tab with an error simply open a working tab.

Logs

No response

Anything else?

No response

wez commented 1 year ago

The error message you shared indicates that you've asked wezterm to spawn something in the local domain.

Can you reproduce this without using gnome hotkeys? Most likely, gnome is running this command from the .desktop file:

https://github.com/wez/wezterm/blob/87a009924c94460f8e78761283bc09e8623b2c44/assets/wezterm.desktop#L8

What wezterm processes are running in between closing and re-opening?

dominz88 commented 1 year ago

Can you reproduce this without using gnome hotkeys?

The problem doesn't appear if i simply run:wezterm connect sysadmin.

Most likely, gnome is running this command from the .desktop file:

That's indeed the case

What wezterm processes are running in between closing and re-opening?

In my local machine, none. On the remote /usr/bin/wezterm-mux-server --pid-file-fd

wez commented 1 year ago

So did you try running wezterm start --cwd . like gnome would?

dominz88 commented 1 year ago

Oh! I apologize, I should've done that. Indeed, that reproduces the problem.

There are no wezterm processes left after i close the tab. So, closing the only/last tab, closes the window and ends the process /usr/bin/wezterm-gui start --cwd .

By the way, thanks for your time and help.

wez commented 1 year ago

I can't reproduce this.

Here's what I tried:

Put this into /tmp/4161.lua:

local wezterm = require 'wezterm'
local config = {}
config.default_domain =  'sysadmin'
config.ssh_domains = {
  {
    name = 'sysadmin',
    remote_address = 'foo',
  },
}

return config

Then ensure that no wezterm processes are running.

Then run wezterm --config-file /tmp/4161.lua start --cwd . Then try close the tab (either via CTRL-D or by clicking the close button on the tab). Then run wezterm --config-file /tmp/4161.lua start --cwd . again.

These steps work as I expect; closing the tab means that the next time I connect a new tab is created. If instead I close the window, reconnecting shows me the tab that I left behind.

Is there something else about your setup that isn't reflected in these steps?

dominz88 commented 1 year ago

Then run wezterm --config-file /tmp/4161.lua start --cwd . Then try close the tab (either via CTRL-D or by clicking the close button on the tab). Then run wezterm --config-file /tmp/4161.lua start --cwd . again.

Yes, thats all there is to it, i've tried using de ubuntu 22 deb package and the appimage. With the same result

dominz88 commented 1 year ago

I did some more tests:

It seems that what ever is going on, it is happening on the wezterm server side. Because:

In other words, if I do the following I still get the error:

I see that the process wezterm-mux-server --pid-file-fd 9 is still running, even after closing the only tab left via any client.

dominz88 commented 1 year ago

I tested the same steps using a fedora vm as ssh domain and still get the same error.

dominz88 commented 1 year ago

Ok after many tests it seems that the problem comes from the parameter "--cwd ." The manual says

--cwd <CWD>
          Specify the current working directory for the initially spawned program

Weirdly enough, it works just fine if my local user and my remote user are the same or is it because the working directory is the same on both sides ( /home/myuser) ?

wez commented 1 year ago

The thing that needs to be resolved and understood is why the local domain is being used at all in your configuration. The cwd parameter itself is not the problem; it's that something is using the local domain for you for some reason.

Try turning up the debugging level:

WEZTERM_LOG=trace wezterm start --cwd . >/tmp/verbose.log  2>&1

this will be very verbose. Please share that resulting log file with me.

dominz88 commented 1 year ago

Hello,

Here is the log file generated during the error, I don't see in it any message related to the problem though.

verbose.log

wez commented 1 year ago

According to this part of the log:

16:13:12.208  INFO   wezterm_gui            > Spawned your command via the existing GUI instance. Use wezterm start --always-new-process if you do not want this behavior. Result=SpawnResponse { tab_id: 2, pane_id: 2, window_id: 1, size: TerminalSize { rows: 24, cols: 80, pixel_width: 640, pixel_height: 384, dpi: 0 } }

you already have a running wezterm instance, and that is being used to satisfy the request. Please include verbose logging from that instance as well!

dominz88 commented 1 year ago

Hello,


 luis@PC-LUIS  ~  WEZTERM_LOG=trace wezterm --config-file wez start --cwd . >/tmp/verbose.log  2>&1
 luis@PC-LUIS  ~  ps awufx | grep wezterm                                                          
luis       10927  0.0  0.0  17888  2688 pts/1    S+   21:15   0:00      |   \_ grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox wezterm
 luis@PC-LUIS  ~  WEZTERM_LOG=trace wezterm --config-file wez start --cwd . >/tmp/verbose.log  2>&1

I reproduced the same problem ensuring there is no instance left between runs. Here are the traces

verbose.log.1.txt verbose.log.2.txt

I also noticed that if i stop the wezterm server between relaunches on my ssh domain the error is not present. Is there a way to enable the debug on the server side ?