-
Notifications
You must be signed in to change notification settings - Fork 18k
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
runtime: signal handling changed by signal.Notify #36420
Comments
Seems the without Given this and the docs in Thoughts? |
What exactly do you mean when you say "SEGV, BUS and FPE handling from external process kill(2) don't work"? What precisely are you doing with your example program, and what precisely happens? |
Without the call |
I do not ever see this program output a stack trace when sent an external signal, even if I remove the call to |
my test app is called kill -SEGV `ps -ef |grep go-signal |grep -v grep | awk '{print $2}'` With ./go-signal
sleep...
sleep...
sleep...
sleep...
sleep...
sleep...
sleep...
sleep...
^Cprocess: interrupt
Got signal: interrupt
^C Without ./go-signal
sleep...
sleep...
sleep...
sleep...
SIGSEGV: segmentation violation
PC=0x4578a3 m=0 sigcode=0
goroutine 5 [syscall]:
runtime.notetsleepg(0x567820, 0x3b9ab614, 0x1415)
/usr/local/go/src/runtime/lock_futex.go:227 +0x34 fp=0xc000044760 sp=0xc000044730 pc=0x409d64
runtime.timerproc(0x567800)
/usr/local/go/src/runtime/time.go:311 +0x2f1 fp=0xc0000447d8 sp=0xc000044760 pc=0x446d11
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc0000447e0 sp=0xc0000447d8 pc=0x455991
created by runtime.(*timersBucket).addtimerLocked
/usr/local/go/src/runtime/time.go:169 +0x10e
goroutine 1 [sleep]:
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:310
time.Sleep(0x3b9aca00)
/usr/local/go/src/runtime/time.go:105 +0x157
main.main()
/home/steveh/code/go-signal/main.go:32 +0xb6
goroutine 18 [syscall]:
os/signal.signal_recv(0x0)
/usr/local/go/src/runtime/sigqueue.go:147 +0x9c
os/signal.loop()
/usr/local/go/src/os/signal/signal_unix.go:23 +0x22
created by os/signal.init.0
/usr/local/go/src/os/signal/signal_unix.go:29 +0x41
rax 0xfffffffffffffffc
rbx 0x3b9ab614
rcx 0xc0000446d8
rdx 0x0
rdi 0x567820
rsi 0x80
rbp 0xc0000446e8
rsp 0xc0000446a0
r8 0x0
r9 0x0
r10 0xc0000446d8
r11 0xc0000446d8
r12 0xff
r13 0xffffffffffffff
r14 0x4dc522
r15 0x38
rip 0x4578a3
rflags 0x206
cs 0x33
fs 0x53
gs 0x2b To clarify in both cases package |
For reference my test is running under WSL uname -a
Linux vader 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux However also had my colleague tested on native |
I am also seeing the same behaviour as mentioned by @stevenh For reference I am running Go version |
Interesting. When I try the same thing, the program simply continues running. Ah, I see. It works the way you describe for Go 1.13, but not for Go tip. The difference is that in Go 1.13 the signal is being received by a G for which When the program does not call Oddly, I think the change in tip is due to the new timers code. With the old timers code the only real thread in this program would sleep in When the program does call I think the question now is: what do we want to happen? Clearly whether the program calls So we need to fix that. Whether But still: what do we want to happen? Historically we have ignored externally generated |
In our case we're looking for feature parity apps built in other languages e.g. sleep...
Terminated SEGV: sleep...
Segmentation fault (core dumped)
sleep...
Bus error (core dumped)
sleep...
Floating point exception (core dumped)
sleep...
Alarm clock
sleep...
Bad system call (core dumped) In summary using the OS native behaviour if we don't handle it. |
Go has already deviated from OS native behavior for signals like |
Agreed, using it as a guide is the most appropriate, as I'm not aware of other languages which have a standard convention to print a stack dump. Another reason is stdout / err generally aren't monitored so the standard way to gain information about a "crash" is the generation of a core dump; there are of course workflows which are but cores always have the ability to work. |
I remember the old behavior, and didn't realize the behavior has changed (probably accidentally). |
I would argue that an external (In fact, I think this may be more-or-less a duplicate of #19465.) |
I came across that when investigating this issue, and agree it's very similar. The notable difference is maintaining compatibility with previously installed |
One way to approach this is to ask what the use case is. There are fairly well-defined use cases for several externally generated signals such as What is the use case for an externally generated |
For This is also the common definition for For |
Note that Go programs don't dump core by default on receipt of any signal, |
Change https://golang.org/cl/228900 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Use signal.Notify to handle os.Interrupt
What did you expect to see?
All other signal handling to be unchanged
What did you see instead?
SEGV, BUS and FPE handling from external process kill(2) don't work if
signal.Notify(...)
is used.Example
This seems related the definition in the runtime of these signals containing
_SigPanic
as those which are defined as_SigThrow
continue to still function correctly; confirmed by changingSEGV
from_SigPanic
to_SigThrow
which then continues to work even oncesignal.Notify(...)
has been called.The text was updated successfully, but these errors were encountered: