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

WSL Terminal always closes immediately - How to debug #156

Closed
kmille opened this issue Feb 27, 2019 · 94 comments
Closed

WSL Terminal always closes immediately - How to debug #156

kmille opened this issue Feb 27, 2019 · 94 comments

Comments

@kmille
Copy link

kmille commented Feb 27, 2019

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

@mintty
Copy link
Owner

mintty commented Feb 27, 2019

See the mintty manual page:
-V
Print version information and exit.
Why did you add that option?

@kmille
Copy link
Author

kmille commented Feb 27, 2019

Hey
that was just a test. I normally run in it without the -V so just
%LOCALAPPDATA%\wsltty\bin\mintty.exe --WSL= --configdir="%APPDATA%\wsltty" -~

@mintty
Copy link
Owner

mintty commented Feb 27, 2019

Add option Hold=always to the config file.

@kmille
Copy link
Author

kmille commented Feb 27, 2019

sry for the late response:
%LOCALAPPDATA%\wsltty\bin\mintty.exe --WSL= --configdir="%APPDATA%\wsltty" -~ -h=always
Should be the same behaviour like using the config.
But I tried this before. No error message for me. The window is just closing again...

@mintty
Copy link
Owner

mintty commented Feb 27, 2019

On the command line, the option is -h always without a =, or -o Hold=always.

@kmille
Copy link
Author

kmille commented Feb 27, 2019

unbenannt

@kmille kmille closed this as completed Feb 27, 2019
@mintty
Copy link
Owner

mintty commented Feb 27, 2019

Sure I like closed issues :) but that does not look like a solution for you‽

@kmille
Copy link
Author

kmille commented Feb 27, 2019

You are right. Sorry

@kmille kmille reopened this Feb 27, 2019
@kmille
Copy link
Author

kmille commented Mar 1, 2019

Hey, it's working again. And I don't know why 😄
Probably Windows domain foo magic or Windows Updates ...

thanks for your support!

@kmille kmille closed this as completed Mar 1, 2019
@kmille
Copy link
Author

kmille commented Mar 14, 2019

hm the problem occurs again -:-
Any ideas what to do with an immediately closing WSL Terminal?

@kmille kmille reopened this Mar 14, 2019
@mintty
Copy link
Owner

mintty commented Mar 14, 2019

We've had the Hold option already, at least it should not close then. You should see some error message or other trace of what happens.
Is this related to #153, #152? Maybe #135? Or rather #142?

@mintty
Copy link
Owner

mintty commented Mar 14, 2019

Did you change the WSL mount path configuration? The solution for #91 might not be sufficient...

@kmille
Copy link
Author

kmille commented Mar 17, 2019

I will try it and give you feedback

@jrhorn424
Copy link

I can connect to other distros fine, but not Alpine.

image

@mintty
Copy link
Owner

mintty commented Mar 21, 2019

Reproduced, also when using wslbridge directly from cygwin.
Navigating to /mnt/c/Users/.../wsltty/bin and trying to run wslbridge-backend directly also fails with ./wslbridge-backend: not found. That's weird; maybe Alpine has a safety policy not to run programs from Windows mounts?
To test the latter assumption, I tried to copy wslbridge-backend into Alpine's /bin but that fails for permission right, also Alpine does not seem to support sudo - maybe it's a "closed shop"?

@Biswa96
Copy link
Contributor

Biswa96 commented Mar 21, 2019

@jrhorn424 From where did you download Alpine? Probable cause, Alpine uses MUSL C library for it's compactness feature. The wslbridge-backend is compiled with GNU C library. So, there is incompatibility between C library. For Alpine, you have to compile the wslbridge-backend from source. This issue may not be related with mintty.

@mintty
Copy link
Owner

mintty commented Mar 21, 2019

Even though the backend Makefile contains options -static-libgcc -static-libstdc++ already?

@Biswa96
Copy link
Contributor

Biswa96 commented Mar 21, 2019

OK, I explain. When I compiled wslbridge-backend in Debian based distributions readelf -d wslbridge-backend shows:

Dynamic section at offset 0xd2898 contains 30 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libutil.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]

Now in Alpine, I did this:

  • Update & upgrade: apk update; apk upgrade
  • Install bash because bash is hard coded in wslbridge: apk add bash bash-completion binutils
  • Install pro tools: apk add alpine-sdk build-base gcc g++ make
  • Apply this StackOverflow answer because MUSL has issue with strerror_r().
  • Make /bin/bash default in /etc/passwd.
  • Compile wslbridge-backend in Alpine.
  • BOOM!

@jrhorn424
Copy link

Thank you, that works for me as well! Very much appreciated.

@kmille
Copy link
Author

kmille commented Mar 25, 2019

I still don't get it. It seems like the wslbridge is the problem. I use Terminus at the moment but it's pretty buggy if I use it with tmux. Should I ask at the wslbridge repo?

@mintty
Copy link
Owner

mintty commented Mar 25, 2019

I've tried to follow Biswa's suggestion and compile wslbridge-backend in Alpine (commented out the strerror stuff) - with no success. You can report it to wslbridge but I wouldn't expect a solution in wslbridge itself (except for the strerror).

@Biswa96
Copy link
Contributor

Biswa96 commented Mar 25, 2019

@mintty Did you install bash in Alpine? Because wslbridge.exe depends on bash.exe which executes /bin/bash only. And Alpine /bin/busybox has not bash.
@kmille's issue is different that @jrhorn424. @kmille is using Ubuntu.

@mintty
Copy link
Owner

mintty commented Mar 25, 2019

OK, right, I overlooked the bash thing in your comment. Got it working.
Then I tried to compile statically again, with the error
wslbridge-backend.cc:(.text.startup+0x115b): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
This is strange. Anyway, I disabled the getpwuid part and, with -static added to the backend Makefile, it works, i.e. wslbridge-backend compiled with gcc (in "normal" WSL, not Alpine). I could also reenable the strerror stuff. So there is in fact an opportunity to cover Alpine with a common wslbridge-backend binary, if only we find a solution for the getpwuid crap.

And, for that matter, this is not the original issue opened here, but that was fuzzy anyway...

@Biswa96
Copy link
Contributor

Biswa96 commented Mar 25, 2019

wslbridge-backend.cc:(.text.startup+0x115b): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

@mintty That is known issue. See here rprichard/wslbridge#26

@mintty
Copy link
Owner

mintty commented Mar 27, 2019

I've tried to load getpwuid with dlopen but it did not work...

@kmille
Copy link
Author

kmille commented Apr 5, 2019

In the mantime: I works again #yail \o/
I still have no clue but I'm sure it's not a problem of mintty. It's probably caused by our domain foo. Thanks it adavance!

@Biswa96
Copy link
Contributor

Biswa96 commented Sep 8, 2019

I have some opinions here Biswa96/wslbridge2#4. Can you guys provide your opinions which is better (or worse)?

@MarkFiveThousand
Copy link

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
Copy link
Owner

mintty commented Sep 10, 2019

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

@mintty
Copy link
Owner

mintty commented Oct 1, 2019

Released 3.0.5.

@mintty
Copy link
Owner

mintty commented Oct 1, 2019

Tentatively closing.

@mintty mintty closed this as completed Oct 1, 2019
@cakira
Copy link

cakira commented Oct 14, 2019

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
Copy link
Owner

mintty commented Oct 14, 2019

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
Copy link

cakira commented Oct 15, 2019

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
Copy link
Contributor

Biswa96 commented Oct 15, 2019

sometimes wslbridge2.exe just returned, silently

  • Did you try with other fresh installed distribution in WSL?
  • Did you try to change the default shell in WSL?
  • What theme or extension are you using in zsh?

@mintty
Copy link
Owner

mintty commented Oct 15, 2019

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
Copy link

cakira commented Oct 15, 2019

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
Copy link
Contributor

Biswa96 commented Oct 15, 2019

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
Copy link

cakira commented Oct 15, 2019

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
Copy link

cakira commented Oct 15, 2019

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
Copy link
Owner

mintty commented Oct 16, 2019

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
Copy link

cakira commented Oct 16, 2019

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
Copy link
Contributor

Biswa96 commented Oct 17, 2019

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
Copy link

cakira commented Oct 22, 2019

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. 😅

@Biswa96
Copy link
Contributor

Biswa96 commented Oct 22, 2019

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
Copy link
Owner

mintty commented Oct 22, 2019

@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
Copy link

seandex commented Oct 22, 2019

@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
Copy link

iverdr17 commented Mar 9, 2020

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

@DanKaplanSES
Copy link

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
Copy link
Contributor

Biswa96 commented Nov 23, 2023

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
Copy link

DanKaplanSES commented Nov 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests