-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Alacritty/Windows] ctrl-c
a process launched in nushell
kills the terminal
#3937
Comments
Is |
it didn't change the behavior
|
I'm not sure then. We've had people report similar issues before but it's usually what I said with the ctrlc_ext. You might search the issues repo to see what others have found. |
This might be due to the fact that nushell doesn't create a new process group when spawning a process There was a similar issue when using the zellij multiplexer with |
Same issue here, but with nushell 0.42.0 build with For me To test I start |
does the same problem exist in |
How do I test that? |
you try out our new engine by compiling it and running it and then trying to reproduce the problem. |
I narrowed down the problem a bit: It happens only when using nu as a shell in a systemd-nspawn container directly! I use that a lot and hardly ever run a shell in my main system, so I had not notices that yet, sorry!
Both |
This is no longer happening in 0.43.0 ❯ version | pivot
────┬────────────────────┬─────────────────────────────────────────────────────────────────────────────────────
# │ Column0 │ Column1
────┼────────────────────┼─────────────────────────────────────────────────────────────────────────────────────
0 │ version │ 0.43.0
1 │ short_commit │ 4e8e0386
2 │ commit_hash │ 4e8e03867c87307d536369a20dbe81491666ee51
3 │ commit_date │ 2022-01-18 17:51:21 +00:00
4 │ build_os │ windows-x86_64
5 │ rust_version │ rustc 1.58.0 (02072b482 2022-01-11)
6 │ rust_channel │ stable-x86_64-pc-windows-msvc
7 │ cargo_version │ cargo 1.58.0 (7f08ace4f 2021-11-24)
8 │ pkg_version │ 0.43.0
9 │ build_time │ 2022-01-18 18:21:27 +00:00
10 │ build_rust_channel │ release
11 │ features │ ctrlc, dataframe, default, rustyline, term, trash, uuid, which, zip
12 │ installed_plugins │ binaryview, chart bar, chart line, fetch, from bson, from sqlite, inc, match, post,
│ │ ps, query json, s3, selector, start, sys, textview, to bson, to sqlite, tree, xpath
────┴────────────────────┴─────────────────────────────────────────────────────────────────────────────────────
|
No change for me in a systemd-nspawn container using
I still see this problem:-/ |
@hunger Can you try again on the latest main branch? Seems fine for me. |
I stil, have that issue with nu at version 44. I run nu in a systemd-nspawn container, start gitk and hit Ctrl-C. Nu quits, the container quits and I am in the shell I ran systemd-nspawn in. Note stat I am on Linux, not windows. |
what about in version 0.59.1? I don't think we're going to fix 0.44 since we're so close to releasing 0.60. |
latest main will be nu 0.59.1 |
Sorry for that, I just did |
no worries - the newest version is in beta. You can read about it here https://www.nushell.sh/blog/2022-03-01-nushell_0_59.html. You can also compile it from the latest main branch of our repo. |
I grabbed the binaries from the blog post you linked to: Exactly the same behavior:-/
|
hmmm, i can't reproduce it but i don't ssh/connect to other machines. i wonder if the ctrl-c is being passed back to the connecting app (ssh or whatever) then the host app is processing the ctrl-c. Coming from a host like powershell and then nushell the ctrl-c would be passed to powershell after nushell exits. so, it kind of makes sense to me. |
It does not happen when I run bash inside the container and start nu in that bash shell. It behaves as espected then: Ctrl-C kills gitk and returns me into nu. That's why I suspect (without any understanding of the problem space:-) that this might be some terminal setup issue or something: If the terminal is set up correctly (by some other shell) then it works. |
I have no clue about shells and terminal, but I suspect that is "just" a "set up the terminal" issue. Windows and Linux are two very different beasts in that regard. I am not surprised that it works in windows. It also works in Linux -- provided it is started inside another shell like bash or fish, even in a container. Started in a container without bash and fish? Nope, it does not work there. Is there anything I can do to help reproduce the issue? |
I don't have a way really to test this on Linux. I could try on WSL2 but I'm not sure that would be the same. |
@fdncred does nushell 0.59 create a new process group when spawning a new process ? If not, then all processes are in the same foreground group, so ctrlc sends the signal to every member of the group -- the behavior is normal |
Up |
No, I don't believe nushell creates a process group as it is starting. |
sooo I guess that's what's causing the problem.. ? |
I'd like to be able to reproduce the problem before saying that's the diagnosis. |
idk about reproducing it with @hunger's setup, but, you might be able to reproduce a similar behavior (unsure because I haven't checked for myself) with zellij 0.14 on linux. More details: zellij-org/zellij#615 (comment) |
Did younuse zellij during your test? Or a container? Nu works fine in a bog-standard terminal on Linux for me as well. |
As I said above, I used WSLg. It's not started as a child process of any other shell. If someone wants to submit a PR to somehow start nushell as a pid group, that works on Mac/Linux/Windows, we'll take a look at it. I myself, am not even sure this is possible since no one is spawning nushell, like in the Zellij example. |
hmm, very much not expert here, but if understand correctly, nushell rather needs to create a pid group for every process it spawns, that way ctrlc doesn't propagate to nushell itself. From the explanation of the folks at zellij when dealing with the issue
Since other shells do that I don't see why it would be impossible for nushell. I am not at all familiar with the internals, but if a core developer directs me to the crate/module that handles that, I can try to submit a PR |
Help me understand better because I don't follow this logic. I thought the problem isn't with nushell's spawned processes like plugins or externals. I thought the problem was with how nushell launched itself. Am I understanding that correctly? Point me to how other shells do this and I'll take a look. BTW - That zellij command is for spawning externals, not for spawning zellij itself. Plus, I believe the call it uses to do that is unix-only. |
I am very much spitballing, this is solely based on my understanding of the small explanation by the zellij contributor (aka paragraph I quoted in my previous comment) My understanding is that zellij 0.14 spawned a pane and shell as part of the same process group. Since nushell doesn't create a process group for its child processes, any command spawned by nushell is part of the same foreground group as nushell itself as well as its parent zellij pane. To circumvent that, they made it so the shell is part of its own process group, separating the parent pane from its shell.
idk... the same explanation by the zellij contributor makes it sound like other shells do it "nushell doesn't create a new process group when spawnning a process" |
just did some testing, here's what I found
# launch nu in zellij and make it sleep
$ env SHELL=nu zellij setup --clean
Welcome to Nushell 0.44.0 (type 'help' for more info)
nushell> ^sleep 8000
# on a separate console
$ pgrep -a sleep
57217 sleep 8000
# find the group id of the sleep process
$ ps -o pid,ppid,pgid,sid,cmd 57217
PID PPID PGID SID CMD
57217 57069 57068 57068 sleep 8000
# list the processes associated with that group id
$ pgrep --pgroup=57068 -a
57068 /home/midnightexigent/.cargo/bin/zellij --server /run/user/1000/zellij/0.14.0/ubiquitous-addition
57069 /usr/bin/nu
57217 sleep 8000 process spawned by nushell finds itself in the same foreground group as the zellij session and nushell itself. ctrlc propagates to the zellij session, killing the pane
# launch nu in zellij and make it sleep
$ env SHELL=nu zellij setup --clean
Welcome to Nushell 0.44.0 (type 'help' for more info)
/home/midnightexigent> ^sleep 8000
# on a separate shell
$ pgrep -a sleep
57534 sleep 8000
$ ps -o pid,ppid,pgid,sid,cmd 57534
PID PPID PGID SID CMD
57534 57478 57478 57478 sleep 8000
$ pgrep --pgroup=57478 -a
57478 /usr/bin/nu
57534 sleep 8000 this time nu and zellij session are in seperate process groups, so ctrlc doesn't propagate to the zellij session
# put zsh to sleep
$ sleep 9000
# on a separate console
$ pgrep -a sleep
57968 sleep 9000
$ ps -o pid,ppid,pgid,sid,cmd 57968
PID PPID PGID SID CMD
57968 51484 57968 51484 sleep 9000
$ pgrep --pgroup=57968 -a
57968 sleep 9000 zsh isn't in the same process group as the process it spawned, so ctrlc sends a signal to only the spawned command |
As to actually implementing this, shouldn't it be relatively straightforward if nushell forks itself before spawning a child process, then waits for the child ? |
Yeah so my last comment is no too far off from the truth. From tutorial on how to write a shell in C
int lsh_launch(char **args)
{
pid_t pid, wpid;
int status;
pid = fork();
if (pid == 0) {
// Child process
if (execvp(args[0], args) == -1) {
perror("lsh");
}
exit(EXIT_FAILURE);
} else if (pid < 0) {
// Error forking
perror("lsh");
} else {
// Parent process
do {
wpid = waitpid(pid, &status, WUNTRACED);
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
}
return 1;
} |
Something like this is worth a try on Linux and Mac but I think |
I am not an expert when it comes to writing shells, but this is so low level that I would be seriously surprised if there was a good cross-platform solution for this:-/ |
I'd leave it untouched on windows since the problem is no longer happening there. I don't think the concepts of process group or kernel signals translate from unix to windows very well either way with the nix crate and conditional compilation it sounds straightforward. but IMO there's gonna be twist since builtin commands aren't other binaries meaning that they are technically the same process as nushell.. |
I can't reproduce this in Windows Terminal on v0.70.1, guessing it's been fixed. Is anyone still having issues with |
I still have exactly the same behavior I originally reported in nu 0.70.0. I do not see 0.70.1 when trying cargo install yet. |
same issue here. Windows Terminal. | key | value |
| ------------------ | ---------------------------------------- |
| version | 0.77.1 |
| branch | |
| commit_hash | 0120e4040d09f3bdffb945fa5fe450b72df7837a |
| build_os | windows-x86_64 |
| build_target | x86_64-pc-windows-msvc |
| rust_version | rustc 1.66.1 (90743e729 2023-01-10) |
| rust_channel | 1.66.1-x86_64-pc-windows-msvc |
| cargo_version | cargo 1.66.1 (ad779e08b 2023-01-10) |
| build_time | 2023-03-17 05:15:37 +00:00 |
| build_rust_channel | release |
| features | default, zip |
| installed_plugins | | |
Some investigation: I wonder if this might just be a "feature" of Windows Terminal. As a user, I expect ctrl-C to interrupt the "currently running thing". (be that a process, or a script running in my shell). But I think Windows Terminal or PowerShell might just be killing the process. For example: If in PowerShell I run:
and press BUT, if I start a new tab in Windows Terminal running NuShell directly, I can run:
And pressing So it seems maybe PowerShell or Windows Terminal is just interpreting Or maybe it's expecting the running process (NuShell) to trap and respond to If I run |
I think the HandlerRoutine callback is relevant here. Specifically, using SetConsoleCtrlHandler to set one. |
I still can't reproduce this on Windows, unfortunately. @ChrisDenton I believe we're already calling Lines 12 to 14 in 7ec5f2f
|
This issue is quite strange. Seemingly, no one on the nushell team has been able to reproduce this, which is leading me to think that there are other configuration components involved. As no one on the team has been able to reproduce this, I'm going ahead and closing. If folks who are experiencing this are able to come up repro steps, please re-open and post the repro steps. |
video.mp4 |
I've been experiencing this for the past few months, and might have a solution for anyone who installed via a package manager like chocolatey or scoop (assuming scoop will do the same thing). My alacritty config was pointing at Chocolatey generates these shims and I suspect they do some funky stuff around spawning that shell (although I'm not going to dig into it). |
Describe the bug
Interestingly, when
nu
is spawned from a parent shell (eg.powershell
), the problem doesn't occurHow to reproduce
alacritty.yml
, set the shell tonu
sleep 10sec
)ctrl-c
to interrupt itExpected behavior
I expect the process to stop without killing the parent terminal
Screenshots
No response
Configuration
Additional context
No response
The text was updated successfully, but these errors were encountered: