mintty / wsltty

Mintty as a terminal for Bash on Ubuntu on Windows / WSL
Other
3.11k stars 104 forks source link

WSL Terminal always closes immediately - How to debug #156

Closed kmille closed 5 years ago

kmille commented 5 years ago

Hey,

my WSL Terminal always closes immediately after starting it and I don't know why or how to debug it. I used wsltty-1.9.6-install.exe to install it. I use the Ubuntu 18.04 Image from the Windows Store on a Windows 10 Laptop.

That's how I call it: H:>%LOCALAPPDATA%\wsltty\bin\mintty.exe --WSL= --configdir="%APPDATA%\wsltty" -~ -V

The config file in "%APPDATA%\wsltty" is emtpy. Can you please help me. I can't go back to the default shell

itsjef commented 5 years ago

I thought so already but I have no idea how to proceed with analysis, remotely.

There is no way to export a dump file too, so sad...

Oh. Well, WSL sometimes needs a while until startup has settled. If you only wait enough...?

My computer has been running 4 days straight, that must be enough startup time 😞

mintty commented 5 years ago

As I asked the original poster earlier: Did you change the WSL mount path configuration? The solution for #91 might not be sufficient...

itsjef commented 5 years ago

I didn't. I don't even have a /etc/wsl.conf file. All of my configurations are default.

I tried creating an empty /etc/wsl.conf file but it didn't have any effect.

cakira commented 5 years ago

I've just hacked a solution! Edit: People are reporting (and I confirmed in a workmate computer) that this solution is not working for them :-(

Problem My wsltty used to work great. However, after I tried (unsuccessfully) using Docker for Windows Desktop, my WSL Terminal started closing immediately. The symptoms are identical to the ones described by the OP.

My setup Windows 10 Pro, Version 1709 - I have administrative rights only on demand wsltty v3.0.2 installed via Chocolatey Ubuntu 18.04 Docker for Windows Desktop (version 2.0.0.31259, I guess) - currently uninstalled

My workaround A created a file %LOCALAPPDATA%\wsltty\bin\wslbridge-hack.bat with the following contents: @%LOCALAPPDATA%\wsltty\bin\wslbridge.exe -t -e APPDATA -C~ Then I changed the WSL Terminal shortcut to: %LOCALAPPDATA%\wsltty\bin\mintty.exe --configdir="%APPDATA%\wsltty" -~ "%LOCALAPPDATA%\wsltty\bin\wslbridge-hack.bat"

Tests I did before finding the workaround I tried uninstalling, reinstalling, wsltty with chocolatey, without success. I tried installing an old version (1.9.6) of wsltty without chocolatey, without success. I tried reinstalling Ubuntu, several times, both with and without reboots between uninstall and installs I tried opening %LOCALAPPDATA%\wsltty\bin\wslbridge.exe in a CMD window. It successfully presented the bash prompt in the CMD window. I tried opening mintty in a CMD window. It opened a new window, with the message "... Failed to run /bin/bash..." I tried openint mintty with mintty.exe cmd.exe. It opened a new window, with the windows command prompt, as expected. I tried openint mintty with mintty.exe notepad.exe. It opened a new window, then a new notepad window, as expected. I tried opening wslbridge with the command 'wslbridge.exe'. The bash prompt appeared in the same window, as expected. I tried opening mintty with mintty.exe .\wslbridge.exe. It opened a new window then immediately closed it. I believe this is exactly the problem. I created a .bat file wslbridge-hack.bat, with the content @%LOCALAPPDATA%\wsltty\bin\wslbridge.exe and executed mintty.exe .\wslbridge-hack.bat. A new window was opened, with the bash prompt! Hooray! 🎉

Then I customized wslbridge-hack.bat, until it was similar to the original shortcut. The solution is the workaround presented above.

Notes I saw no wslbridge.exe.stackdump file anywhere. Now, I have a side effect of a new window asking for confirmation when I click in the Terminal window close button.

tynanbe commented 5 years ago

See https://github.com/mintty/wsltty/issues/169#issuecomment-514691889 for a potential fix for musl-based distros (Alpine, Void-musl, etc.).

itsjef commented 5 years ago

@cakira I got this message when running your workaround before the window closed itself.

wslbridge warning: GetVersionEx reports version 6.2 -- is wslbridge.exe properly manifested?

However, when I check my Windows version with [environment]::OSVersion.Version, it showed:

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      18362  0

instead of Major=6 and Minor=2 according to wslbridge.cc. I wonder if this is a wslbridge problem instead of wsltty's

cakira commented 5 years ago

Hi @itsjef ! I'm not sure about what is happening in your case. I guess our problems are different. If I open a CMD window and execute %LOCALAPPDATA%\wsltty\bin\wslbridge.exe the bash prompt is shown in the current window. Does this happen to you too?

For reference, if I execute %LOCALAPPDATA%\wsltty\bin\mintty.exe --version and %LOCALAPPDATA%\wsltty\bin\wslbridge.exe --version, the results are, in order: _mintty 3.0.2 (x8664-pc-cgwin - wsltty 3.0.2 and wslbridge 0.2.5-dev

itsjef commented 5 years ago

Hi @cakira, this is the output when I ran those commands.

image

For %LOCALAPPDATA%\wsltty\bin\mintty.exe --version, a window popped up showing the mintty.exe's version. %LOCALAPPDATA%\wsltty\bin\wslbridge.exe --version worked fine too. However %LOCALAPPDATA%\wsltty\bin\wslbridge.exe as showed.

mintty commented 5 years ago

%LOCALAPPDATA%\wsltty\bin\wslbridge

Works here. The message probably is a result of wslbridge-backend failing to run a shell. Which wsltty version was that? Do you have the capability to compile wslbridge-backend and add some debug stuff?

itsjef commented 5 years ago

Which wsltty version was that?

I'm using 3.0.2. I will try to complie wslbridge-backend myself and report later

itsjef commented 5 years ago

@mintty I compiled both wslbridge and wslbridge-backend myself, this time %LOCALAPPDATA%\wsltty\bin\wslbridge worked. However, when I double-clicked on the WSL Terminal shortcut (modified following to @cakira's workaround), it still closed immediately with the same wslbridge warning: GetVersionEx reports version 6.2 -- is wslbridge.exe properly manifested? message.

mintty commented 5 years ago

Can you also compile the frontend (cygwin environment needed)? Try to set up unconditional usage of output pipe, in line 1204:

-    if (windowsVersion() >= std::make_tuple(10u, 0u, 15063u)) {
+    if (1 || windowsVersion() >= std::make_tuple(10u, 0u, 15063u)) {
itsjef commented 5 years ago

@mintty I compiled the frontend after modifying the condition and replaced the %LOCALAPPDATA%\wsltty\bin\wslbridge. The window still closed right after I opened it.

Strange thing is, every once or twice it just functions normally and doesn't close on itself without any sign before or after. 😕

itsjef commented 5 years ago

@mintty When I tried running wslbridge.exe -t -e APPDATA -C ~ from CMD, I would be prompted with a Bash shell as the WSL opened successfully. However, when I created a wslbridge.bat file with that line as its content, then double-clicked to open it, a window would appear and close immediately, just like when I clicked on the WSL Terminal.lnk shortcut.

Strange thing is, occasionally, the window wouldn't close and there would be a Bash shell as if no error happened.

Noted that then I ran the wslbridge.bat file from CMD/Powershell, it would work all the time, just like running wslbridge.exe -t -e APPDATA -C ~ directly.

I wonder if there is a relationship between this behavior and the issue we are discussing?

I'm using WSLtty version 3.0.2.3, fresh installation, by the way.

mintty commented 5 years ago

I wonder if there is a relationship between this behavior and the issue we are discussing?

Probably yes, so thanks for your observations.

takamiyoshi commented 5 years ago

Hi guys,

I am suffering from the similar symptoms that the window opened and closed immediately in wsltty, currently 3.0.2.3. I started with the 3.0.0 version a few month ago, then it worked fine a while. Now It did not. I reinstalled 3.0.0 and even 1.9.X, but all versions showed the same symptoms.

From my observation, the "TrendMicro Virus Buster (Internet security)" did something wrong. When I stopped the virus buster, wsltty launched as I expected. Any idea to fix?

@cakira I tried your suggestions, but it did not change at all. My Linux distribution is Ubuntu 18.04

itsjef commented 5 years ago

@takamiyoshi Wow, I'm having Trend Micro (Security Agent) on my machine too. Sadly, I can't uninstall or stop it due to company policy.

takamiyoshi commented 5 years ago

I asked my company to test if Trend Micro was the reason. Same situation, I can not uninstall/stop it for my work. Interestingly, it worked before with Trend Micro, but now not. I do not know when the symptom started.

I have found the post, and it said "exclusion of scanning" might resolve the issue. Then I tried on my computer to set exclusion of scanning at the directory %LOCALAPPDATA%\wsltty, not successful. Also our IT did something on their side (not really sure what they did), not successful.

During the re-installing process of Trend Micro, I had the instance without Trend Micro, then it worked fine!!..

So stressful.

cakira commented 5 years ago

Hi! My new workmate also have this problem and my solution didn't work for him too. :-( He started using cmdr instead, and I even tried it for the sake for uniformity, but cmdr is not my thing.

I can confirm that we have Trend Micro Security Agent too, but I have not the permission to unload it. And in my computer, wsltty is working steady after applying my solution.

Biswa96 commented 5 years ago

I have some opinions here https://github.com/Biswa96/wslbridge2/issues/4. Can you guys provide your opinions which is better (or worse)?

MarkFiveThousand commented 5 years ago

Does it strike anyone else as odd that the message below that is supposed to contain the substring '/bin/bash' is getting overwritten with random data. This smells like a memory overwrite error in wslbridge. That would jive with the intermittent nature of the problem in addition to reports of other people having similar difficulties with wslbridge used in other apps.

C:\Users\mhodges\AppData\Local\wsltty\bin>wslbridge.exe error: could not exec '/b□/□$': No such file or directory

C:\Users\mhodges\AppData\Local\wsltty\bin>wslbridge.exe error: could not exec '/b□□': No such file or directory

mintty commented 5 years ago

Thanks for the observation. It seems wslbridge is not maintained anymore, but the next wsltty release will switch to wslbridge2.

mintty commented 5 years ago

Released 3.0.5.

mintty commented 5 years ago

Tentatively closing.

cakira commented 5 years ago

Hi! Just to report, I upgraded my Windows 10 from 1703 to 1903 and upgraded wsltty to version 3.0.6, via chocolatey. At first, it worked flawlessly. Then, after 3 ou 4 days, it reverted to the buggy behavior of closing by itself.

I tried to investigate, but I was discouraged when I saw that a command that worked once stopped working after just a few minutes. I'll try investigating again in a couple days.

mintty commented 5 years ago

Is that with WSL 2? (Output of wsl -l -v) Closing by itself means: immediately, after clicking the desktop shortcut? If you add a -h alw option to the shortcut target, any diagnostic information? What version does Options - About report in that case?

cakira commented 5 years ago

I'm using WSL 1, since WSL 2 isn't available to my Windows version (Windows 1903 Build 18362). I tried to repeat my own procedure above and it didn't work because sometimes wslbridge2.exe just returned, silently, as below:

C:\Users\cakira>%LOCALAPPDATA%\wsltty\bin\wslbridge2.exe

C:\Users\cakira>

and sometimes it started a WSL session, as below (I use the fish shell in my WSL):

C:\Users\cakira>%LOCALAPPDATA%\wsltty\bin\wslbridge2.exe
Welcome to fish, the friendly interactive shell⏎
/m/c/U/cakira  

So, I wrote a script just to have an idea of how often wslbridge2 works. The batch script is:

@ECHO OFF
set count=0
:loop
set /a count=%count% + 1
echo wslbridge2 test count: %count%
%LOCALAPPDATA%\wsltty\bin\wslbridge2.exe
goto loop

And the results are:

C:\Users\cakira>%LOCALAPPDATA%\wsltty\bin\retry.bat
wslbridge2 test count: 1
wslbridge2 test count: 2
Welcome to fish, the friendly interactive shell⏎
/m/c/U/cakira 
wslbridge2 test count: 3
wslbridge2 test count: 4
wslbridge2 test count: 5
wslbridge2 test count: 6
wslbridge2 test count: 7
wslbridge2 test count: 8
wslbridge2 test count: 9
wslbridge2 test count: 10
wslbridge2 test count: 11
wslbridge2 test count: 12
wslbridge2 test count: 13
wslbridge2 test count: 14
wslbridge2 test count: 15
wslbridge2 test count: 16
wslbridge2 test count: 17
wslbridge2 test count: 18
wslbridge2 test count: 19
Welcome to fish, the friendly interactive shell⏎
/m/c/U/cakira 
wslbridge2 test count: 20
wslbridge2 test count: 21
wslbridge2 test count: 22
Welcome to fish, the friendly interactive shell⏎
/m/c/U/cakira 
wslbridge2 test count: 23
wslbridge2 test count: 24
wslbridge2 test count: 25
wslbridge2 test count: 26
wslbridge2 test count: 27
Welcome to fish, the friendly interactive shell⏎
/m/c/U/cakira 
wslbridge2 test count: 28
wslbridge2 test count: 29
wslbridge2 test count: 30
wslbridge2 test count: 31
wslbridge2 test count: 32
wslbridge2 test count: 33
Welcome to fish, the friendly interactive shell⏎
/m/c/U/cakira 
wslbridge2 test count: 34
Welcome to fish, the friendly interactive shell⏎
/m/c/U/cakira 
wslbridge2 test count: 35
wslbridge2 test count: 36
wslbridge2 test count: 37
wslbridge2 test count: 38
wslbridge2 test count: 39
wslbridge2 test count: 40
wslbridge2 test count: 41
wslbridge2 test count: 42
wslbridge2 test count: 43
wslbridge2 test count: 44
wslbridge2 test count: 45
wslbridge2 test count: 46
wslbridge2 test count: 47
wslbridge2 test count: 48
wslbridge2 test count: 49
wslbridge2 test count: 50
wslbridge2 test count: 51
Welcome to fish, the friendly interactive shell⏎
/m/c/U/cakira 
wslbridge2 test count: 52
wslbridge2 test count: 53
wslbridge2 test count: 54
wslbridge2 test count: 55
wslbridge2 test count: 56
wslbridge2 test count: 57
wslbridge2 test count: 58
Welcome to fish, the friendly interactive shell⏎
/m/c/U/cakira  

(I formated a little the results above, just to fit the screen and I also typed CTRL-D after every WSL session)

I guess my next step should be compiling wslbridge2 and debugging it, but I'm afraid of installing cygwin, cygwin gcc and everything.

As a side note, I tried to use Windows Terminal, but mintty is still the best, by far!

Biswa96 commented 5 years ago

sometimes wslbridge2.exe just returned, silently

mintty commented 5 years ago

You are not supposed to run wslbridge2 from a Windows cmd console session, that's not its purpose. You could simply call wsl in that case, without mintty of course. Or you can invoke mintty (via its wsltty installation) and it will implicitly involve wslbridge2.

cakira commented 5 years ago

sometimes wslbridge2.exe just returned, silently

* Did you try with other fresh installed distribution in WSL?

No, I didn't try a fresh install since my upgrade to Windows 1903 last week. Reinstalling and reconfiguring the distribution isn't a light operation to me and when I tried it in July, it didn't change anything regarding wsltty.

* Did you try to change the default shell in WSL?

I've just tried to change the default shell back to bash. The buggy behavior persists with bash.

* What theme or extension are you using in `zsh`?

I don't use zsh. I use fish shell.

Biswa96 commented 5 years ago

Oh, mistake, I mean did you install any theme in fish shell?

Reinstalling and reconfiguring the distribution isn't a light operation to me

You can install any distribution without using Windows Store, just for a test. There are many here in GitHub. I have tested wslbridge2 with Debian, Ubuntu, Alpine with zsh, fish, bash etc without any error.

cakira commented 5 years ago

You are not supposed to run wslbridge2 from a Windows cmd console session, that's not its purpose.

Thank you for your attention. In this case, I was just trying to troubleshoot my buggy instance of wsltty, the same way as I did in July.

My tests point that mintty is just fine, but wslbridge2 only works about 15% of the times it is executed.

Or you can invoke mintty (via its wsltty installation) and it will implicitly involve wslbridge2.

Yep! But it will fail most of the time in my computer. (If I add -h alw to the shortcut target, mintty opens with no contents) However, as a quick (and very very dirty 🙈) fix, I changed my batch script to execute mintty (with the same parameters as the shortcut) several times. Most of the executions will fail, but one or another will succeed and open the mintty terminal as intended.

cakira commented 5 years ago

You can install any distribution without using Windows Store, just for a test. There are many here in GitHub. I have tested wslbridge2 with Debian, Ubuntu, Alpine with zsh, fish, bash etc without any error.

I tried Debian right now and it had the same behavior as Ubuntu: it opens only once in a few tries.

Oh, mistake, I mean did you install any theme in fish shell?

Not a theme, but I use fish-prompt-metro and it includes some Unicode characters in my prompt, similar to Powerline.

mintty commented 5 years ago

So maybe we need to raise the Windows Build prerequisite? And wsltty could revert to wslbridge(1) for earlier versions, i.e. still for the current official, non-insider Windows release (which doesn't support WSL V2 yet, I think)?

cakira commented 5 years ago

For reference, I uninstalled wsltty 3.0.6 and tried version 1.9.6, that I used a long time ago. Version 1.9.6 had the same behavior as 3.0.6: %LOCALAPPDATA%\wsltty\bin\wslbridge.exe fails silently most of the time, but once in a while, it opens the shell.

By the way, my wsltty used to work like a breeze some time ago. Then I tried to install docker for windows in my computer and that screwed up my wsltty.

Biswa96 commented 5 years ago

I have tested wsltty in a fresh installed Windows 10 1903 VM with fresh Debian from Windows Store, no packages are added or updated. It works flawlessly. Contributions are always welcomed in wslbridge2.

cakira commented 5 years ago

Hello! Just to give a feedback on my problem (the terminal closes immediately most of the time, but not always): After debugging, I found that the problem is in wslbridge2. In tag v0.4, the file wslbridge-backend.cpp contains the function below:

static int connectSocket(int port) {
    const int s = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);

    const int flag = 1;
    const int nodelayRet = setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
    assert(nodelayRet == 0);

    sockaddr_in addr = {};
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
    const int connectRet = connect(s, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr));
    assert(connectRet == 0);

    return s;
}

If the function connect(s, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)); executes when port = outputSocketPort, most of the times wslbridge will crash, even thought connect() returns zero.

I will open an issue in wslbridge2 to ask if someone could help me further debug this issue.

Thank you very much for your support!

Edit: _only now I realized that it was the owner of wslbridge2 that was replying to my messages. Shame on me. :sweatsmile:

Biswa96 commented 5 years ago

I can not reproduce the error. Can you get the error code? Just add a line fatalPerror("connect"); in between connect and assert.

I will open an issue in wslbridge2 to ask if someone could help me further debug this issue.

Always welcome. But need another one case of this same error.

mintty commented 5 years ago

@seandex, this is twofold the wrong issue to report your case. This is not the wsl-terminal project and this issue is not about virus reports.

seandex commented 5 years ago

@seandex, this is twofold the wrong issue to report your case. This is not the wsl-terminal project and this issue is not about virus reports.

oooops, i deleted the post. I apologize!

iverdr17 commented 4 years ago

try by uninstalling using cmd administrator and reinstalling wsl --unregister Ubuntu-18.04

DanKaplanSES commented 11 months ago

This would've saved me a minute or two: You put the -h always before the last argument. e.g., %LOCALAPPDATA%\wsltty\bin\mintty.exe --tabbar=4 --WSL="Ubuntu" --configdir="%APPDATA%\wsltty" -h always -

The first few comments make it seem like you can put -h always at the end, but that doesn't work.

Anyway, now that I can read the error message ("...WSL 2 requires an update to its kernel component..."), should I remove the -h always or leave it there?

Biswa96 commented 11 months ago

Anyway, now that I can read the error message ("...WSL 2 requires an update to its kernel component...")

Please use the WSL from Microsoft Store or from here https://github.com/microsoft/WSL/releases

In newer version of Windows, the Linux kernel binary was removed. Hence, that error message.

DanKaplanSES commented 11 months ago

Anyway, now that I can read the error message ("...WSL 2 requires an update to its kernel component...")

Please use the WSL from Microsoft Store or from here https://github.com/microsoft/WSL/releases

In newer version of Windows, the Linux kernel binary was removed. Hence, that error message.

I have been using the Microsoft store version for months and this just happened today. I think it may have been corrupted from my computer crashing a couple days ago. Uninstalling WSL and then manually installing the upgrade with the link in that error message fixed the issue for me.

nullromo commented 1 month ago

This issue popped back up for me yesterday. The program closes straight away, but I can still access WSL through Windows Terminal. I also tried re-running the WSLTTY installer, but it didn't seem to help.

EDIT: I think #356 is a good place to monitor for this.