golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.38k stars 17.71k forks source link

runtime: signal_amd64x.go:76 SIGINT on darwin/amd64 causes segfault under c-shared library #13034

Closed glycerine closed 8 years ago

glycerine commented 9 years ago

A refinement of the report in https://github.com/golang/go/issues/13028 to focus on the OSX-only segfault that happens when I send SIGINT to program that has a c-shared library loaded.

Details: jaten@Jasons-MacBook-Pro:~$ go version # at tip. Also happens in go1.5.1. go version devel +79a3b56 Thu Oct 22 21:19:43 2015 +0000 darwin/amd64

On OSX Yosemite, 10.10.5, darwin amd64.

I built a c-shared library (source code: https://github.com/glycerine/rmq), loaded it under R (a large C program), then called from C into the c-shared go library. Inside the library we start a web-server and the do ListenAndServe(). I have established signal handlers in the go code for SIGINT. However pressing ctrl-c and sending SIGINT to the process results in a segfault on OSX, but not on linux.

Under gdb on osx, I observe that the segfault is isolated to go1.6-dev/src/runtime/signal_amd64x.go:76, the value of c is out of bounds in the line if c.sigcode() != _SI_USER && flags&_SigPanic != 0 {.

context of the segfault, at signal_amd64x.go:76 
...
// May run during STW, so write barriers are not allowed.                                                
//go:nowritebarrier                                                                                      
func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
    _g_ := getg()
    c := &sigctxt{info, ctxt}

    if sig == _SIGPROF {
        sigprof(uintptr(c.rip()), uintptr(c.rsp()), 0, gp, _g_.m)
        return
    }

    if GOOS == "darwin" {
        // x86-64 has 48-bit virtual addresses. The top 16 bits must echo bit 47.                        
        // The hardware delivers a different kind of fault for a malformed address                       
        // than it does for an attempt to access a valid but unmapped address.   
        // OS X 10.9.2 mishandles the malformed address case, making it look like                        
        // a user-generated signal (like someone ran kill -SEGV ourpid).                                 
        // We pass user-generated signals to os/signal, or else ignore them.                             
        // Doing that here - and returning to the faulting code - results in an                          
        // infinite loop. It appears the best we can do is rewrite what the kernel                       
        // delivers into something more like the truth. The address used below                           
        // has very little chance of being the one that caused the fault, but it is                      
        // malformed, it is clearly not a real pointer, and if it does get printed                       
        // in real life, people will probably search for it and find this code.                          
        // There are no Google hits for b01dfacedebac1e or 0xb01dfacedebac1e                             
        // as I type this comment.                                                                       
        if sig == _SIGSEGV && c.sigcode() == _SI_USER {
            c.set_sigcode(_SI_USER + 1)
            c.set_sigaddr(0xb01dfacedebac1e)
        }
    }

    flags := int32(_SigThrow)
    if sig < uint32(len(sigtable)) {
        flags = sigtable[sig].flags
    }
=>  if c.sigcode() != _SI_USER && flags&_SigPanic != 0 {   <<<<< segfaulting here
        // Make it look like a call to the signal func.                                                  
        // Have to pass arguments out of band since                                                      
        // augmenting the stack frame would break                                                        
        // the unwinding code.                                                                           
        gp.sig = sig
        gp.sigcode0 = uintptr(c.sigcode())
 ...
(gdb) handle SIGINT pass
SIGINT is used by the debugger.
Are you sure you want to change it? (y or n) y
Signal        Stop  Print   Pass to program Description
SIGINT        Yes   Yes Yes     Interrupt
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x00000001053b89a9 in runtime.sighandler (sig=537083904, info=0x14003b, ctxt=0x38000051901,
    gp=0xffffffff0538a380) at /Users/jaten/pkg/go1.6-dev/src/runtime/signal_amd64x.go:76
(gdb) p c
$1 = (runtime.sigctxt *) 0x53be72f
(gdb) p flags
$2 = 4
(gdb) p _SigPanic
No symbol "_SigPanic" in current context.
(gdb) p _SI_USER
No symbol "_SI_USER" in current context.
(gdb) p *c
Cannot access memory at address 0x53be72f
(gdb) 

a backtrace from gdb:

(gdb) bt
#0  0x00000001053b89a9 in runtime.sighandler (sig=537083904, info=0x14003b, ctxt=0x38000051901, 
    gp=0xffffffff0538a380) at /Users/jaten/pkg/go1.6-dev/src/runtime/signal_amd64x.go:76
#1  <signal handler called>
#2  0x00000001053d630c in runtime.mach_semaphore_wait ()
    at /Users/jaten/pkg/go1.6-dev/src/runtime/sys_darwin_amd64.s:407
#3  0x00000001053a2a15 in runtime.semasleep1 (ns=-1, ~r1=0)
    at /Users/jaten/pkg/go1.6-dev/src/runtime/os1_darwin.go:385
#4  0x00000001053c9f89 in runtime.semasleep.func1 ()
    at /Users/jaten/pkg/go1.6-dev/src/runtime/os1_darwin.go:401
#5  0x00000001053d2b4b in runtime.systemstack ()
    at /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:278
#6  0x00000001053a2a96 in runtime.semasleep (ns=-1, ~r1=0)
    at /Users/jaten/pkg/go1.6-dev/src/runtime/os1_darwin.go:402
#7  0x00000001053893b0 in runtime.notesleep (n=0xc820034110)
    at /Users/jaten/pkg/go1.6-dev/src/runtime/lock_sema.go:169
#8  0x00000001053ab37e in runtime.stoplockedm () at /Users/jaten/pkg/go1.6-dev/src/runtime/proc.go:1586
#9  0x00000001053ac38e in runtime.schedule () at /Users/jaten/pkg/go1.6-dev/src/runtime/proc.go:1908
#10 0x00000001053ac80b in runtime.park_m (gp=0xc820000600)
    at /Users/jaten/pkg/go1.6-dev/src/runtime/proc.go:2016
#11 0x00000001053d2a7b in runtime.mcall () at /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:204
#12 0x00007fff5fbfd2b8 in ?? ()
#13 0x00000001053d469a in runtime.cgocallback ()
    at /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:712
#14 0x0000000105373f28 in _cgoexp_7e71d05b448d_ListenAndServe (a=0x7fff5fbfd378, n=32)
    at rmq/_obj/_cgo_gotypes.go:490
#15 0x00000001054fa43d in crosscall2 () at /Users/jaten/pkg/go1.6-dev/src/runtime/cgo/asm_amd64.s:36
#16 0x00007fff5fbfd378 in ?? ()
#17 0x0000000000000020 in ?? ()
#18 0x0000000103c9bff8 in ?? ()
#19 0x00007fff5fbfd3b0 in ?? ()
#20 0x0000000104d2ad80 in ?? ()
#21 0x0000000104d2abc0 in ?? ()
#22 0x0000000104d2b6d0 in ?? ()
#23 0x0000000104d241c8 in ?? ()
#24 0x0000000104d2b6d0 in ?? ()
#25 0x0000000104d241c8 in ?? ()
#26 0x00007fff5fbfd3b0 in ?? ()
#27 0x000000010537087e in ListenAndServe (p0=0x2203, p1=0x8, p2=0x9)
    at /var/folders/2x/hm9gp5ys3k9gmm5f_vzm_6wc0000gn/T/go-build514057958/rmq/_obj/_cgo_export.c:21
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) 

The signal handling Go code for SIGINT consisted of either one or two prior calls to signal.Notify().

A full stack dump from pressing ctrl-c generates a seg-fault with this stack trace not under gdb:


R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin14.5.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> options(STERM='iESS', editor='emacsclient')
> require(rmq)
Loading required package: rmq
> require(testthat)
Loading required package: testthat
> handler = function(x) {
+   print(paste("handler called back with argument x = ", paste(collapse=" ",sep=" ",x)))
+   reply=list()
+   reply$hi = "there!"
+   reply$yum = c(1.1, 2.3)
+   reply$input = x
+   reply
+ }
> options(error=recover)
> r = .Call("ListenAndServe", "127.0.0.1:9090", handler, new.env(), package="rmq")
ListenAndServe listening on address '127.0.0.1:9090'...
  C-c C-cfatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x140043 pc=0x10bb1d9a9]

runtime stack:
runtime.throw(0x10c206480, 0x2a)
    /Users/jaten/pkg/go1.6-dev/src/runtime/panic.go:527 +0x90
runtime.sigpanic()
    /Users/jaten/pkg/go1.6-dev/src/runtime/sigpanic_unix.go:12 +0x5a
runtime.sighandler(0xc820032000, 0x14003b, 0xd800051001, 0xffffffff0bb24260)
    /Users/jaten/pkg/go1.6-dev/src/runtime/signal_amd64x.go:76 +0x139

goroutine 17 [select, locked to thread]:
runtime.gopark(0x10c24d868, 0xc82005de00, 0x10c152430, 0x6, 0xc82017a218, 0x2)
    /Users/jaten/pkg/go1.6-dev/src/runtime/proc.go:202 +0x163 fp=0xc82005dad0 sp=0xc82005daa8
runtime.selectgoImpl(0xc82005de00, 0x0, 0x18)
    /Users/jaten/pkg/go1.6-dev/src/runtime/select.go:392 +0xa64 fp=0xc82005dc78 sp=0xc82005dad0
runtime.selectgo(0xc82005de00)
    /Users/jaten/pkg/go1.6-dev/src/runtime/select.go:212 +0x12 fp=0xc82005dc98 sp=0xc82005dc78
main.ListenAndServe(0x7ffb64cba578, 0x7ffb648dc548, 0x7ffb648e5120, 0x7ffb648e4840)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/rmq.go:178 +0x866 fp=0xc82005ded0 sp=0xc82005dc98
runtime.call32(0x0, 0x7fff5687b3d8, 0x7fff5687b468, 0x20)
    /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:442 +0x3e fp=0xc82005def8 sp=0xc82005ded0
runtime.cgocallbackg1()
    /Users/jaten/pkg/go1.6-dev/src/runtime/cgocall.go:264 +0x10c fp=0xc82005df30 sp=0xc82005def8
runtime.cgocallbackg()
    /Users/jaten/pkg/go1.6-dev/src/runtime/cgocall.go:177 +0xd7 fp=0xc82005df90 sp=0xc82005df30
runtime.cgocallback_gofunc(0x0, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:799 +0x60 fp=0xc82005dfa0 sp=0xc82005df90
runtime.goexit()
    /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:1805 +0x1 fp=0xc82005dfa8 sp=0xc82005dfa0

goroutine 6 [syscall]:
os/signal.signal_recv(0x0)
    /Users/jaten/pkg/go1.6-dev/src/runtime/sigqueue.go:112 +0x132
os/signal.loop()
    /Users/jaten/pkg/go1.6-dev/src/os/signal/signal_unix.go:22 +0x18
created by os/signal.init.1
    /Users/jaten/pkg/go1.6-dev/src/os/signal/signal_unix.go:28 +0x37

goroutine 18 [select, locked to thread]:
runtime.gopark(0x10c24d868, 0xc82002ef28, 0x10c152430, 0x6, 0x10bb0c118, 0x2)
    /Users/jaten/pkg/go1.6-dev/src/runtime/proc.go:202 +0x163
runtime.selectgoImpl(0xc82002ef28, 0x0, 0x18)
    /Users/jaten/pkg/go1.6-dev/src/runtime/select.go:392 +0xa64
runtime.selectgo(0xc82002ef28)
    /Users/jaten/pkg/go1.6-dev/src/runtime/select.go:212 +0x12
runtime.ensureSigM.func1()
    /Users/jaten/pkg/go1.6-dev/src/runtime/signal1_unix.go:227 +0x324
runtime.goexit()
    /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:1805 +0x1

goroutine 19 [chan receive]:
main.init.1.func1(0xc820144180)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/rmq.go:43 +0x44
created by main.init.1
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/rmq.go:48 +0xd3

goroutine 34 [syscall, locked to thread]:
runtime.goexit()
    /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:1805 +0x1

goroutine 35 [IO wait]:
net.runtime_pollWait(0x10ce01118, 0x72, 0xc820014210)
    /Users/jaten/pkg/go1.6-dev/src/runtime/netpoll.go:157 +0x60
net.(*pollDesc).Wait(0xc820147a30, 0x72, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/net/fd_poll_runtime.go:73 +0x3a
net.(*pollDesc).WaitRead(0xc820147a30, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/net/fd_poll_runtime.go:78 +0x36
net.(*netFD).accept(0xc8201479d0, 0x0, 0x10cab1888, 0xc8200bb1e0)
    /Users/jaten/pkg/go1.6-dev/src/net/fd_unix.go:408 +0x27c
net.(*TCPListener).AcceptTCP(0xc82013a028, 0xc820192d78, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/net/tcpsock_posix.go:254 +0x4d
net.(*TCPListener).Accept(0xc82013a028, 0x0, 0x0, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/net/tcpsock_posix.go:264 +0x3d
net/http.(*Server).Serve(0xc820182000, 0x10cd7c070, 0xc82013a028, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/net/http/server.go:1907 +0x118
vendor/github.com/glycerine/go-tigertonic.(*Server).Serve(0xc820182000, 0x10cd7c070, 0xc82013a028, 0x0, 0x0)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/vendor/github.com/glycerine/go-tigertonic/server.go:160 +0xe1
vendor/github.com/glycerine/go-tigertonic.(*Server).ListenAndServe(0xc820182000, 0x0, 0x0)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/vendor/github.com/glycerine/go-tigertonic/server.go:144 +0x1e2
main.(*WebServer).Start.func1(0xc820170080)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/web.go:54 +0x25
created by main.(*WebServer).Start
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/web.go:60 +0x4e

Process R exited abnormally with code 2 at Fri Oct 23 01:03:07 2015


R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin14.5.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> options(STERM='iESS', editor='emacsclient')
> require(rmq)
Loading required package: rmq
> require(testthat)
Loading required package: testthat
> handler = function(x) {
+   print(paste("handler called back with argument x = ", paste(collapse=" ",sep=" ",x)))
+   reply=list()
+   reply$hi = "there!"
+   reply$yum = c(1.1, 2.3)
+   reply$input = x
+   reply
+ }
> options(error=recover)
> r = .Call("ListenAndServe", "127.0.0.1:9090", handler, new.env(), package="rmq")
ListenAndServe listening on address '127.0.0.1:9090'...
require(rmq)
  C-c C-cfatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x140043 pc=0x1108849a9]

runtime stack:
runtime.throw(0x110f6d480, 0x2a)
    /Users/jaten/pkg/go1.6-dev/src/runtime/panic.go:527 +0x90
runtime.sigpanic()
    /Users/jaten/pkg/go1.6-dev/src/runtime/sigpanic_unix.go:12 +0x5a
runtime.sighandler(0xc820032000, 0x14003b, 0x23000025101, 0xffffffff00000000)
    /Users/jaten/pkg/go1.6-dev/src/runtime/signal_amd64x.go:76 +0x139

goroutine 17 [select, locked to thread]:
runtime.gopark(0x110fb4868, 0xc820061e00, 0x110eb9430, 0x6, 0xc82001e518, 0x2)
    /Users/jaten/pkg/go1.6-dev/src/runtime/proc.go:202 +0x163 fp=0xc820061ad0 sp=0xc820061aa8
runtime.selectgoImpl(0xc820061e00, 0x0, 0x18)
    /Users/jaten/pkg/go1.6-dev/src/runtime/select.go:392 +0xa64 fp=0xc820061c78 sp=0xc820061ad0
runtime.selectgo(0xc820061e00)
    /Users/jaten/pkg/go1.6-dev/src/runtime/select.go:212 +0x12 fp=0xc820061c98 sp=0xc820061c78
main.ListenAndServe(0x7f9f3ab02578, 0x7f9f39f44748, 0x7f9f39f4a920, 0x7f9f39f4a040)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/rmq.go:178 +0x866 fp=0xc820061ed0 sp=0xc820061c98
runtime.call32(0x0, 0x7fff51b0f3d8, 0x7fff51b0f468, 0x20)
    /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:442 +0x3e fp=0xc820061ef8 sp=0xc820061ed0
runtime.cgocallbackg1()
    /Users/jaten/pkg/go1.6-dev/src/runtime/cgocall.go:264 +0x10c fp=0xc820061f30 sp=0xc820061ef8
runtime.cgocallbackg()
    /Users/jaten/pkg/go1.6-dev/src/runtime/cgocall.go:177 +0xd7 fp=0xc820061f90 sp=0xc820061f30
runtime.cgocallback_gofunc(0x0, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:799 +0x60 fp=0xc820061fa0 sp=0xc820061f90
runtime.goexit()
    /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:1805 +0x1 fp=0xc820061fa8 sp=0xc820061fa0

goroutine 6 [syscall]:
os/signal.signal_recv(0x0)
    /Users/jaten/pkg/go1.6-dev/src/runtime/sigqueue.go:112 +0x132
os/signal.loop()
    /Users/jaten/pkg/go1.6-dev/src/os/signal/signal_unix.go:22 +0x18
created by os/signal.init.1
    /Users/jaten/pkg/go1.6-dev/src/os/signal/signal_unix.go:28 +0x37

goroutine 18 [select, locked to thread]:
runtime.gopark(0x110fb4868, 0xc82002ef28, 0x110eb9430, 0x6, 0x110873118, 0x2)
    /Users/jaten/pkg/go1.6-dev/src/runtime/proc.go:202 +0x163
runtime.selectgoImpl(0xc82002ef28, 0x0, 0x18)
    /Users/jaten/pkg/go1.6-dev/src/runtime/select.go:392 +0xa64
runtime.selectgo(0xc82002ef28)
    /Users/jaten/pkg/go1.6-dev/src/runtime/select.go:212 +0x12
runtime.ensureSigM.func1()
    /Users/jaten/pkg/go1.6-dev/src/runtime/signal1_unix.go:227 +0x324
runtime.goexit()
    /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:1805 +0x1

goroutine 19 [chan receive]:
main.init.1.func1(0xc820140180)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/rmq.go:43 +0x44
created by main.init.1
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/rmq.go:48 +0xd3

goroutine 34 [syscall, locked to thread]:
runtime.goexit()
    /Users/jaten/pkg/go1.6-dev/src/runtime/asm_amd64.s:1805 +0x1

goroutine 8 [IO wait]:
net.runtime_pollWait(0x111819850, 0x72, 0xc820014210)
    /Users/jaten/pkg/go1.6-dev/src/runtime/netpoll.go:157 +0x60
net.(*pollDesc).Wait(0xc820064220, 0x72, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/net/fd_poll_runtime.go:73 +0x3a
net.(*pollDesc).WaitRead(0xc820064220, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/net/fd_poll_runtime.go:78 +0x36
net.(*netFD).accept(0xc8200641c0, 0x0, 0x111a60100, 0xc8200bb200)
    /Users/jaten/pkg/go1.6-dev/src/net/fd_unix.go:408 +0x27c
net.(*TCPListener).AcceptTCP(0xc820030098, 0xc820040d78, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/net/tcpsock_posix.go:254 +0x4d
net.(*TCPListener).Accept(0xc820030098, 0x0, 0x0, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/net/tcpsock_posix.go:264 +0x3d
net/http.(*Server).Serve(0xc82001a0c0, 0x1118199d0, 0xc820030098, 0x0, 0x0)
    /Users/jaten/pkg/go1.6-dev/src/net/http/server.go:1907 +0x118
vendor/github.com/glycerine/go-tigertonic.(*Server).Serve(0xc82001a0c0, 0x1118199d0, 0xc820030098, 0x0, 0x0)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/vendor/github.com/glycerine/go-tigertonic/server.go:160 +0xe1
vendor/github.com/glycerine/go-tigertonic.(*Server).ListenAndServe(0xc82001a0c0, 0x0, 0x0)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/vendor/github.com/glycerine/go-tigertonic/server.go:144 +0x1e2
main.(*WebServer).Start.func1(0xc820017800)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/web.go:54 +0x25
created by main.(*WebServer).Start
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/web.go:60 +0x4e

Process R exited abnormally with code 2 at Fri Oct 23 01:06:56 2015

another, earlier, example of the same thing:

$ R
R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin14.5.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> options(STERM='iESS', editor='emacsclient')
> require(rmq)
Loading required package: rmq
> require(testthat)
Loading required package: testthat
> handler = function(x) {
+   print(paste("handler called back with argument x = ", paste(collapse=" ",sep=" ",x)))
+   reply=list()
+   reply$hi = "there!"
+   reply$yum = c(1.1, 2.3)
+   reply$input = x
+   reply
+ }
> options(error=recover)
> r = .Call("ListenAndServe", "127.0.0.1:9090", handler, new.env(), package="rmq")
ListenAndServe listening on address '127.0.0.1:9090'...
  C-c C-cfatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x8 pc=0x10dd976d9]

runtime stack:
runtime.throw(0x10e425c20, 0x2a)
    /usr/local/go/src/runtime/panic.go:527 +0x90
runtime.sigpanic()
    /usr/local/go/src/runtime/sigpanic_unix.go:12 +0x5a
runtime.sighandler(0xc820032000, 0x0, 0x0, 0x3)
    /usr/local/go/src/runtime/signal_amd64x.go:76 +0x139

goroutine 17 [select, locked to thread]:
runtime.gopark(0x10e468a70, 0xc820061e00, 0x10e37e638, 0x6, 0xc82001e718, 0x2)
    /usr/local/go/src/runtime/proc.go:185 +0x163 fp=0xc820061ad0 sp=0xc820061aa8
runtime.selectgoImpl(0xc820061e00, 0x0, 0x18)
    /usr/local/go/src/runtime/select.go:392 +0xa64 fp=0xc820061c78 sp=0xc820061ad0
runtime.selectgo(0xc820061e00)
    /usr/local/go/src/runtime/select.go:212 +0x12 fp=0xc820061c98 sp=0xc820061c78
main.ListenAndServe(0x7ffd733c4178, 0x7ffd730ddd48, 0x7ffd730e3920, 0x7ffd730e3040)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/rmq.go:161 +0x865 fp=0xc820061ed0 sp=0xc820061c98
runtime.call32(0x0, 0x7fff545f43d8, 0x7fff545f4468, 0x20)
    /usr/local/go/src/runtime/asm_amd64.s:437 +0x3e fp=0xc820061ef8 sp=0xc820061ed0
runtime.cgocallbackg1()
    /usr/local/go/src/runtime/cgocall.go:252 +0x10c fp=0xc820061f30 sp=0xc820061ef8
runtime.cgocallbackg()
    /usr/local/go/src/runtime/cgocall.go:177 +0xd7 fp=0xc820061f90 sp=0xc820061f30
runtime.cgocallback_gofunc(0x0, 0x0, 0x0)
    /usr/local/go/src/runtime/asm_amd64.s:801 +0x60 fp=0xc820061fa0 sp=0xc820061f90
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:1696 +0x1 fp=0xc820061fa8 sp=0xc820061fa0

goroutine 8 [select, locked to thread]:
runtime.gopark(0x10e468a70, 0xc82002f728, 0x10e37e638, 0x6, 0x18, 0x2)
    /usr/local/go/src/runtime/proc.go:185 +0x163
runtime.selectgoImpl(0xc82002f728, 0x0, 0x18)
    /usr/local/go/src/runtime/select.go:392 +0xa64
runtime.selectgo(0xc82002f728)
    /usr/local/go/src/runtime/select.go:212 +0x12
runtime.ensureSigM.func1()
    /usr/local/go/src/runtime/signal1_unix.go:227 +0x323
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:1696 +0x1

goroutine 6 [syscall]:
os/signal.loop()
    /usr/local/go/src/os/signal/signal_unix.go:22 +0x18
created by os/signal.init.1
    /usr/local/go/src/os/signal/signal_unix.go:28 +0x37

goroutine 9 [IO wait]:
net.runtime_pollWait(0x10edd6950, 0x72, 0xc820014210)
    /usr/local/go/src/runtime/netpoll.go:157 +0x60
net.(*pollDesc).Wait(0xc82011c060, 0x72, 0x0, 0x0)
    /usr/local/go/src/net/fd_poll_runtime.go:73 +0x3a
net.(*pollDesc).WaitRead(0xc82011c060, 0x0, 0x0)
    /usr/local/go/src/net/fd_poll_runtime.go:78 +0x36
net.(*netFD).accept(0xc82011c000, 0x0, 0x10f061038, 0xc8201200e0)
    /usr/local/go/src/net/fd_unix.go:408 +0x27c
net.(*TCPListener).AcceptTCP(0xc820122000, 0xc82003cd88, 0x0, 0x0)
    /usr/local/go/src/net/tcpsock_posix.go:254 +0x4d
net.(*TCPListener).Accept(0xc820122000, 0x0, 0x0, 0x0, 0x0)
    /usr/local/go/src/net/tcpsock_posix.go:264 +0x3d
net/http.(*Server).Serve(0xc82008f040, 0x10f061000, 0xc820122000, 0x0, 0x0)
    /usr/local/go/src/net/http/server.go:1887 +0xb3
vendor/github.com/glycerine/go-tigertonic.(*Server).Serve(0xc82008f040, 0x10f061000, 0xc820122000, 0x0, 0x0)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/vendor/github.com/glycerine/go-tigertonic/server.go:160 +0xd8
vendor/github.com/glycerine/go-tigertonic.(*Server).ListenAndServe(0xc82008f040, 0x0, 0x0)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/vendor/github.com/glycerine/go-tigertonic/server.go:144 +0x1e2
main.(*WebServer).Start.func1(0xc820017d80)
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/web.go:54 +0x25
created by main.(*WebServer).Start
    /Users/jaten/pkg/R-3.2.2/src/library/Recommended/rmq/src/rmq/web.go:60 +0x4e

goroutine 18 [syscall, locked to thread]:
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:1696 +0x1

Process R exited abnormally with code 2 at Thu Oct 22 13:47:58 2015
$
glycerine commented 9 years ago

I'm getting sporadic crashes (on linux, fedora22 amd64) on my host R process shutdown. It appears that SIGCHLD is occassionally intercepted by the cshared-library-go runtime. Not sure if this should be addressed along with this ticket or distinct issue. If the fix for this ticket involves allowing the host to avoid guest doing any signal handling at all then the SIGCHLD intercept below would be fixed automatically.

Stack trace from the SIGCHLD interception, is here:

(gdb) bt
#0  runtime.sigaltstack () at /home/jaten/pkg/go1.5.1/src/runtime/sys_linux_amd64.s:355
#1  0x00007ffff14dfc00 in runtime.signalstack (s=0xc820000300)
    at /home/jaten/pkg/go1.5.1/src/runtime/os1_linux.go:337
#2  0x00007ffff14df5d5 in runtime.minit () at /home/jaten/pkg/go1.5.1/src/runtime/os1_linux.go:216
#3  0x00007ffff14e7768 in runtime.needm (x=0 '\000')
    at /home/jaten/pkg/go1.5.1/src/runtime/proc1.go:968
#4  0x00007ffff1513696 in runtime.cgocallback_gofunc ()
    at /home/jaten/pkg/go1.5.1/src/runtime/asm_amd64.s:742
#5  0x00007ffff15135ca in runtime.cgocallback () at /home/jaten/pkg/go1.5.1/src/runtime/asm_amd64.s:714
#6  0x00007ffff14f719b in runtime.badsignal (sig=17)
    at /home/jaten/pkg/go1.5.1/src/runtime/sigqueue.go:169
#7  0x00007ffff14f6212 in runtime.sigtrampgo (sig=17, info=0x672f70, ctx=0x672e40)
    at /home/jaten/pkg/go1.5.1/src/runtime/signal_linux.go:90
#8  0x00007ffff151537b in runtime.sigtramp ()
    at /home/jaten/pkg/go1.5.1/src/runtime/sys_linux_amd64.s:234
#9  0x00007ffff1515380 in runtime.sigtramp ()
    at /home/jaten/pkg/go1.5.1/src/runtime/sys_linux_amd64.s:235
#10 0x0000000000000001 in ?? ()
#11 0x0000000000000000 in ?? ()
(gdb)
gopherbot commented 8 years ago

CL https://golang.org/cl/17903 mentions this issue.

gopherbot commented 8 years ago

CL https://golang.org/cl/18062 mentions this issue.