elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.74k stars 303 forks source link

Elvish is hanging forever. ^C doesn't work #1485

Open ezh opened 2 years ago

ezh commented 2 years ago

I'm trying to figure out how to pass an array as an argument to the command.

And I created a statement when elvish is hanging. And the only way is kill -9 from somewhere.

❯ var x = [a b c]; put (all)

That's it. After Enter, the process will stuck.

Mac x86

put $buildinfo
▶ [&version=0.17.0 &reproducible=$false &go-version=go1.17.3]
sw_vers
ProductName:    macOS
ProductVersion: 12.1
BuildVersion:   21C52

Could someone check, please?

aca commented 2 years ago

c-d works fine. which makes sense since all is waiting for value output from stdin

ezh commented 2 years ago

Confirm. But isn't SIGINT should terminate STDIN as well? CTRL-D is an EOF character. The current behavior reminds me very old telnet protocol from 80-x. 🤔 If it is expected and shell should ignore CTRL-C then I'll close the ticket.

NB The SIGINT signal is sent to a process by its controlling terminal when a user wishes to interrupt the process.

krader1961 commented 2 years ago

Your put (all) isn't on the RHS of a pipeline so it's reading from stdin; i.e., it's waiting for you to type something. Presumably you meant put $x | put (all).

At the moment signals are processed only at a couple of specific points in the REPL lifecycle and those don't include reading from stdin. TBD is how to improve signal processing. FWIW, the way Kornshell (ksh) handles this is via siglongjmp. A truly awful mechanism from the perspective of trying to reason about the behavior of the code.

ezh commented 2 years ago

@krader1961 🙏 It is clear. Feel free to close this ticket if you think this fix/improvement is out of development scope.

krader1961 commented 2 years ago

Feel free to close this ticket if you think this fix/improvement is out of development scope.

The current behavior is definitely suboptimal so this issue should remain open -- at least until it is subsumed by a different issue or otherwise resolved. The current Ctrl-c behavior definitely needs improvement. I noticed this problem long ago when I started to use Elvish. I didn't open an issue because in practice it is rarely a problem for me personally and I usually recognize what I did wrong and terminate the shell via some other mechanism (e.g., closing the terminal).