Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock on ssh_domain connect when stdout is printed from remote .bashrc #1860

Closed
tycho-kirchner opened this issue Apr 11, 2022 · 5 comments
Labels
bug Something isn't working fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. multiplexer

Comments

@tycho-kirchner
Copy link

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

Linux X11

WezTerm version

20220408-101518-b908e2dd

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

Hi, and thanks for this gorgeous project!
I encountered the following issue: when connecting via ssh_domains and the remote bashrc prints something to stdout, a deadlock occurs.
The following is printed, before it is stuck:

Connecting to $HOST using SSH
Using libssh-rs to connect to$USER@$HOST:$PORT
SSH-2.0-OpenSSH_8.4
Running: wezterm cli proxy
Checking server version

When the echo line is removed from remote ~/.bashrc, everything is fine.

To Reproduce

On the remote host, put the following to the beginning of ~/.bashrc (bash must be ssh's login shell)

echo foobar

On localhost, add the respective ssh_domain to wezterm's config file (configure remote_hostname as usual in ~/.ssh/config)

ssh_domains = {
    {
      name = "remote-test",
      remote_address = "remote_hostname",
    },
}

Then on localhost execute wezterm connect remote-test, to see it deadlock.

Configuration

see above.

Expected Behavior

No deadlock (:

Logs

No response

Anything else?

No response

@tycho-kirchner tycho-kirchner added the bug Something isn't working label Apr 11, 2022
@wez
Copy link
Owner

wez commented Apr 11, 2022

stdout is reserved for the mux protocol when using an ssh_domain.

In general, you should avoid printing to stdout from your shell rcfiles as this sort of thing can impact a variety of different programs, not just wezterm!

If you must output stuff from your rcfiles, I would recommend making it conditional on being an interactive shell, and outputting to stderr instead of stdout.

@tycho-kirchner
Copy link
Author

Thanks for the quick response. In fact usually I'm far from being dependent on printing stuff to stdout from my bashrc - that was just a relict from a recent debug session 😅. Maybe wezterm/multiplexing.html is a good place to document that? Btw. in my experience the following is usually better than checking for interactive flags case $- in *i*):

# Put to the beginning of the bashrc.
if [[ -n ${BASH_EXECUTION_STRING+x} && $BASH_EXECUTION_STRING == 'wezterm'* ]] ; then
    return 0
fi

wez added a commit that referenced this issue Apr 12, 2022
Use some heuristics to verify the data that is about to be parsed;
this can help to detect eg: data being output to stdout prior
to us sending any encoded data to the remote mux.

In addition, add a timeout to help avoid waiting forever in
the case that we didn't detect a problem.

refs: #1860
@wez
Copy link
Owner

wez commented Apr 12, 2022

I've added some logic to try to detect this case and error out more quickly with a hint:

; wezterm connect somewhere
21:11:12.177  ERROR  wezterm_client::client > going to run wezterm cli proxy
21:11:12.271  ERROR  wezterm_client::client > Error while decoding response pdu: decoding a PDU: decode_raw: Corrupt Response
21:11:12.401  ERROR  wezterm_client::domain > detached domain 3
21:11:12.401  ERROR  mux                    > domain detached panes: []
21:11:12.428  ERROR  wezterm_gui            > Internal channel was closed prior to sending request. This may indicate that the remote host output invalid data to stdout prior to running the requested command; terminating
21:11:12.428  ERROR  mux::connui            > while running ConnectionUI loop: recv_timeout: channel is empty and disconnected

@wez wez added multiplexer fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. labels Apr 12, 2022
@wez wez closed this as completed Apr 17, 2022
@tycho-kirchner
Copy link
Author

Thanks @wez . Just tried it and indeed see above output. Personally, I'm fine with the
Corrupt Response hint, however, to be even more clear it may be desirable to print an ascii-representation of the exact corrupt response. Anyway, thanks so far 🙂.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. multiplexer
Projects
None yet
Development

No branches or pull requests

2 participants