-
Notifications
You must be signed in to change notification settings - Fork 760
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
Strange character sequences (ANSI escape sequences?) leaking into shell prompt when starting/attaching Tmux #2275
Comments
Please also note that there are already a lot of related issues/reports but not in this repository.
Some links to the reports that I found:
Other relevant links:
So my conclusions are the following:
|
On |
Thanks for the additional data @yoctozepto! :) I think it's the combination of the terminal and OpenSSH for Windows but that the actual bug is in OpenSSH for Windows and the terminal only matters as it will affect the response to tmux's I did run two additional tests yesterday:
To be sure I did another test today via Ubuntu 24.04 LTS in WSL 2: I installed and started
PS: I can also trigger the bug with
|
OK, so it truly is the Win32-OpenSSH - that is the common denominator here. It needs certain conditions to happen but it does not happen without it. |
Sounds like a tmux bug to me. It is normal and expected behaviour that sending to a VT100-style terminal a device-attributes request of the form If an application like tmux sends such a request, it has to wait for and parse the entire response, and not cause it to echo back to the terminal for the user to see. This waiting and parsing by tmux doesn't seem to happen correctly here. The question is why tmux doesn't swallow the response. On my old Linux xterm, I get back
On Windows Terminal on current Windows 11, I get instead
Different numbers, but still correct syntax that tmux should swallow. I don't think this is anything that OpenSSH gets involved in. Instead, I suspect that the VT100 terminal emulation built into Windows Terminal (or ConPTY?) is returning something that tmux didn't expect, even though it looks syntactically correct to me. Check in the source code of tmux the state machine that is meant to process the reply to that request. |
@primeos-work That is expected behaviour and not a bug. (Or you could say it's a bug in your use of the echo command ... ;-) Your echo command asked the terminal to reply to a device-attributes request and then finished without reading the reply. So the reply now goes to the shell, which didn't expect it and treats it like user keyboard entry. |
Since the issue seems random, could it be that the speed at which these characters are produced/transferred is causing it? As in, tmux does not wait long enough for the consumption. |
Yes, that seems likely, and would explain reports that increasing the tmux configuration parameter escape-time alleviates the problem for many users. Looking at tmux/tty-keys.c, the unit for Looking at Nagle's algorithm, I suspect There may be a conflict of interest with vi users who may have to wait for |
One thing Windows Terminal and ConPTY folks might want to check is if their device-attributes response is really being sent out via a single |
Looking in Windows Terminal at terminal/src/terminal/adaptDispatch.cpp:AdaptDispatch::DeviceAttributes() and _ReturnCsiResponse we can see where the device-attributes response of Windows Terminal comes from. It is one wide string |
Maybe try something like this, although last time I was asked about anything like this it turned out the terminal was sending the response twice, so you would want to be sure that is not happening (tmux logs or strace tmux is the easiest way):
|
@nicm Thanks for the suggestion. I would probably modify it to more something like
such that you don't override an even higher user preference for that delay. |
I do still wonder, however, why this does not trigger when WSL2 SSH is run in Windows Terminal. Maybe only then do the bytes get sent in different packets or buffered too long? Could it have to do with Windows networking? Especially how it runs (or doesn't run) the Nagle's algorithm? |
@yoctozepto If you run ssh in WSL2, you use the Linux-kernel implementation of TCP, which does all kinds of very clever things, like the I can't find anything similar mentioned among the Windows TCP features. (If you are really curious, try disabling TCP autocorking in WSL2 with |
Yup, this is why I am suggesting it might be the Windows vs Linux networking subsystem that causes the discrepancy.
Checked - but it has no effect on the outcome. |
Prerequisites
Steps to reproduce
Connect to a Linux/Unix host via
ssh
and attach to atmux
session. Strangely the results seem to differ based on the target OS, e.g.:61;6;7;21;22;23;24;28;32;42c
(basically every time)0;10;1c
but only on every third/fourth attempt or soExpected behavior
I can attach to my Tmux session and it looks exactly as I left it.
This usually means that the last line of the active Tmux window/pane contains a empty shell prompt like this:
Actual behavior
I get some additional random characters ("garbage") behind the prompt, e.g.:
Error details
No response
Environment data
I am using the Windows Terminal and it doesn't matter if I uses the "Windows PowerShell", "Command Prompt", or "Git Bash". When I use "Git Bash" via "Windows Terminal" everything works as expected with
/usr/bin/ssh
(OpenSSH_9.7p1, OpenSSL 3.2.1 30 Jan 2024) but not with/c/Program\ Files/OpenSSH/ssh
(OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2) which is why I came to the conclusion that this seems to be a OpenSSH for Windows bug. The second indication that this seems to be an OpenSSH for Windows bug is that I didn't get those unexpected character sequence withSSH_TERM_CONHOST_PARSER=0
(but that also makes the rendering much much slower and I get significant visual glitches like a green background color (probably due to the status line background color from tmux)).Anyway, here is the desired output but I don't expect it to be relevant in this case:
Version
OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2
Visuals
No response
The text was updated successfully, but these errors were encountered: