go-qml / qml

QML support for the Go language
Other
1.96k stars 189 forks source link

Hangs and Crashes when starting another process #89

Closed cookieo9 closed 9 years ago

cookieo9 commented 9 years ago

I've only tested this on darwin/amd64 using go tip and 1.3.1, it may not happen elsewhere.

Attempting to start a new process (eg: via os/exec.Command) will cause either a crash or a hang when qml is running.

Sample Code: http://play.golang.org/p/eUoef9S3e4

The DoClick button executes the sub-proccess (just a simple echo command) in the code called directly by qml. It causes a crash: "fatal error: runtime: stack growth during syscall"

The GoDoClick button does the same work, but in a new goroutine, it simply causes the app to hang forever and eat up CPU. Hitting CTRL-\ properly causes go to print a stack trace and exit.

cookieo9 commented 9 years ago

Full crash output:

FOO!
fatal error: runtime: stack growth during syscall

runtime stack:
runtime.throw(0x4235c53)
    /Users/cookieo9/local/go/src/pkg/runtime/panic.c:510 +0x79 fp=0x7fff5fbf9a28 sp=0x7fff5fbf9a10
runtime.newstack()
    /Users/cookieo9/local/go/src/pkg/runtime/stack.c:903 +0x8d9 fp=0x7fff5fbf9b70 sp=0x7fff5fbf9a28
runtime.morestack()
    /Users/cookieo9/local/go/src/pkg/runtime/asm_amd64.s:282 +0x61 fp=0x7fff5fbf9b78 sp=0x7fff5fbf9b70

goroutine 1 [stack growth, locked to thread]:
syscall.Syscall6(0x7, 0x21bf, 0xc20803369c, 0x0, 0xc208068630, 0x0, 0x0, 0x407a83a, 0x60, 0x0)
    /Users/cookieo9/local/go/src/pkg/syscall/asm_darwin_amd64.s:44 +0x5 fp=0xc208033600 sp=0xc2080335f8
syscall.wait4(0x21bf, 0xc20803369c, 0x0, 0xc208068630, 0x4169ec0, 0x0, 0x0)
    /Users/cookieo9/local/go/src/pkg/syscall/zsyscall_darwin_amd64.go:32 +0x7d fp=0xc208033660 sp=0xc208033600
syscall.Wait4(0x21bf, 0xc2080336e4, 0x0, 0xc208068630, 0xc20804e4e0, 0x0, 0x0)
    /Users/cookieo9/local/go/src/pkg/syscall/syscall_bsd.go:162 +0x64 fp=0xc2080336a8 sp=0xc208033660
os.(*Process).wait(0xc20804e4e0, 0x0, 0x0, 0x0)
    /Users/cookieo9/local/go/src/pkg/os/exec_unix.go:22 +0x108 fp=0xc208033750 sp=0xc2080336a8
os.(*Process).Wait(0xc20804e4e0, 0x0, 0x0, 0x0)
    /Users/cookieo9/local/go/src/pkg/os/doc.go:45 +0x39 fp=0xc208033778 sp=0xc208033750
os/exec.(*Cmd).Wait(0xc20807a140, 0x0, 0x0)
    /Users/cookieo9/local/go/src/pkg/os/exec/exec.go:357 +0x1eb fp=0xc208033850 sp=0xc208033778
os/exec.(*Cmd).Run(0xc20807a140, 0x0, 0x0)
    /Users/cookieo9/local/go/src/pkg/os/exec/exec.go:239 +0x70 fp=0xc208033880 sp=0xc208033850
main.Foo.DoClick()
    /Users/cookieo9/bad-qml.go:24 +0xc5 fp=0xc208033908 sp=0xc208033880
main.Foo.DoClick·i(0x0)
    <autogenerated>:3 +0x27 fp=0xc208033910 sp=0xc208033908
runtime.call16(0x415cdc8, 0xc2080300d0, 0x800000008)
    /Users/cookieo9/local/go/src/pkg/runtime/asm_amd64.s:416 +0x32 fp=0xc208033928 sp=0xc208033910
reflect.Value.call(0x415cd20, 0x0, 0x0, 0x138, 0x4179120, 0x4, 0xc20807a000, 0x0, 0xa, 0x0, ...)
    /Users/cookieo9/local/go/src/pkg/reflect/value.go:566 +0x1214 fp=0xc208033cb8 sp=0xc208033928
reflect.Value.Call(0x415cd20, 0x0, 0x0, 0x138, 0xc20807a000, 0x0, 0xa, 0x0, 0x0, 0x0)
    /Users/cookieo9/local/go/src/pkg/reflect/value.go:414 +0xd6 fp=0xc208033d20 sp=0xc208033cb8
gopkg.in/qml%2ev1.hookGoValueCallMethod(0x607cd40, 0xc20804c120, 0x0, 0x7fff5fbf9ca0)
    /Users/cookieo9/local/go-ext/src/gopkg.in/qml.v1/bridge.go:507 +0x4a8 fp=0xc208033f88 sp=0xc208033d20
----- stack segment boundary -----
runtime.cgocallbackg1()
    /Users/cookieo9/local/go/src/pkg/runtime/cgocall.c:271 +0xd0 fp=0xc20801be20 sp=0xc20801bdc8
runtime.cgocallbackg()
    /Users/cookieo9/local/go/src/pkg/runtime/cgocall.c:243 +0x50 fp=0xc20801be30 sp=0xc20801be20
runtime.cgocallback_gofunc(0x4060291, 0x4001930, 0xc20801bea8)
    /Users/cookieo9/local/go/src/pkg/runtime/asm_amd64.s:859 +0x5a fp=0xc20801be40 sp=0xc20801be30
runtime.asmcgocall(0x4001930, 0xc20801bea8)
    /Users/cookieo9/local/go/src/pkg/runtime/asm_amd64.s:762 +0x41 fp=0xc20801be48 sp=0xc20801be40
runtime.cgocall(0x4001930, 0xc20801bea8)
    /Users/cookieo9/local/go/src/pkg/runtime/cgocall.c:143 +0x111 fp=0xc20801be90 sp=0xc20801be48
gopkg.in/qml%2ev1._Cfunc_applicationExec(0x415bb80)
    gopkg.in/qml.v1/_obj/_cgo_defun.c:71 +0x33 fp=0xc20801bea8 sp=0xc20801be90
gopkg.in/qml%2ev1.Run(0x41b0a08, 0x0, 0x0)
    /Users/cookieo9/local/go-ext/src/gopkg.in/qml.v1/bridge.go:61 +0x1ba fp=0xc20801bf08 sp=0xc20801bea8
main.main()
    /Users/cookieo9/bad-qml.go:11 +0x29 fp=0xc20801bf40 sp=0xc20801bf08
runtime.main()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:259 +0x137 fp=0xc20801bfa8 sp=0xc20801bf40
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc20801bfb0 sp=0xc20801bfa8

goroutine 2 [syscall]:
runtime.notetsleepg(0xc20801df70, 0xdf8475800)
    /Users/cookieo9/local/go/src/pkg/runtime/lock_sema.c:273 +0x88 fp=0xc20801df48 sp=0xc20801df18
runtime.MHeap_Scavenger()
    /Users/cookieo9/local/go/src/pkg/runtime/mheap.c:668 +0x99 fp=0xc20801dfa8 sp=0xc20801df48
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc20801dfb0 sp=0xc20801dfa8
created by runtime.main
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:219

goroutine 3 [GC sweep wait]:
runtime.park(0x40708b0, 0x4243b58, 0x4235fdb, 0xd)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1421 +0xa7 fp=0xc208019f50 sp=0xc208019f40
runtime.parkunlock(0x4243b58, 0x4235fdb, 0xd)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1437 +0x47 fp=0xc208019f78 sp=0xc208019f50
bgsweep()
    /Users/cookieo9/local/go/src/pkg/runtime/mgc0.c:1114 +0xd2 fp=0xc208019fa8 sp=0xc208019f78
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc208019fb0 sp=0xc208019fa8
created by runtime.gc
    /Users/cookieo9/local/go/src/pkg/runtime/mgc0.c:1332

goroutine 4 [finalizer wait]:
runtime.park(0x40708b0, 0x4243b40, 0x4236134, 0xe)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1421 +0xa7 fp=0xc208039f08 sp=0xc208039ef8
runtime.parkunlock(0x4243b40, 0x4236134, 0xe)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1437 +0x47 fp=0xc208039f30 sp=0xc208039f08
runfinq()
    /Users/cookieo9/local/go/src/pkg/runtime/mgc0.c:1667 +0xf4 fp=0xc208039fa8 sp=0xc208039f30
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc208039fb0 sp=0xc208039fa8
created by runtime.gc
    /Users/cookieo9/local/go/src/pkg/runtime/mgc0.c:1332

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc208036fb0 sp=0xc208036fa8

goroutine 5 [semacquire]:
runtime.park(0x40708b0, 0x424b940, 0x4232a60, 0xa)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1421 +0xa7 fp=0xc208017de0 sp=0xc208017dd0
runtime.parkunlock(0x424b940, 0x4232a60, 0xa)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1437 +0x47 fp=0xc208017e08 sp=0xc208017de0
runtime.semacquire(0xc20800c35c, 0x408f101)
    /Users/cookieo9/local/go/src/pkg/runtime/sema.goc:140 +0x131 fp=0xc208017e78 sp=0xc208017e08
sync.runtime_Semacquire(0xc20800c35c)
    /Users/cookieo9/local/go/src/pkg/runtime/sema.goc:199 +0x30 fp=0xc208017e90 sp=0xc208017e78
sync.(*Mutex).Lock(0xc20800c358)
    /Users/cookieo9/local/go/src/pkg/sync/mutex.go:66 +0xd2 fp=0xc208017eb8 sp=0xc208017e90
gopkg.in/qml%2ev1.(*Window).Wait(0xc20800c380)
    /Users/cookieo9/local/go-ext/src/gopkg.in/qml.v1/qml.go:868 +0xa6 fp=0xc208017ee0 sp=0xc208017eb8
main.run(0x0, 0x0)
    /Users/cookieo9/bad-qml.go:47 +0x171 fp=0xc208017f68 sp=0xc208017ee0
gopkg.in/qml%2ev1.func·002()
    /Users/cookieo9/local/go-ext/src/gopkg.in/qml.v1/bridge.go:58 +0x48 fp=0xc208017fa8 sp=0xc208017f68
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc208017fb0 sp=0xc208017fa8
created by gopkg.in/qml%2ev1.Run
    /Users/cookieo9/local/go-ext/src/gopkg.in/qml.v1/bridge.go:60 +0x1b3
exit status 2
cookieo9 commented 9 years ago

Full Hang Output (killed with CTRL-):

FOO!
SIGQUIT: quit
PC=0x407fe4b

goroutine 0 [idle]:
runtime.mach_semaphore_wait()
    /Users/cookieo9/local/go/src/pkg/runtime/sys_darwin_amd64.s:395 +0xb fp=0xb0093df0 sp=0xb0093de8
runtime.semasleep(0xffffffffffffffff)
    /Users/cookieo9/local/go/src/pkg/runtime/os_darwin.c:416 +0xb5 fp=0xb0093e20 sp=0xb0093df0
runtime.notesleep(0x42446a0)
    /Users/cookieo9/local/go/src/pkg/runtime/lock_sema.c:175 +0xff fp=0xb0093e40 sp=0xb0093e20
sysmon()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:2625 +0x27e fp=0xb0093e88 sp=0xb0093e40
runtime.mstart()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:655 +0x113 fp=0xb0093e98 sp=0xb0093e88

goroutine 1 [syscall, locked to thread]:
runtime.cgocallbackg()
    /Users/cookieo9/local/go/src/pkg/runtime/cgocall.c:244 +0x55 fp=0xc20801be30 sp=0xc20801be20
runtime.cgocallback_gofunc(0x405fa91, 0x4001130, 0xc20801bea8)
    /Users/cookieo9/local/go/src/pkg/runtime/asm_amd64.s:859 +0x5a fp=0xc20801be40 sp=0xc20801be30
runtime.asmcgocall(0x4001130, 0xc20801bea8)
    /Users/cookieo9/local/go/src/pkg/runtime/asm_amd64.s:762 +0x41 fp=0xc20801be48 sp=0xc20801be40
runtime.cgocall(0x4001130, 0xc20801bea8)
    /Users/cookieo9/local/go/src/pkg/runtime/cgocall.c:143 +0x111 fp=0xc20801be90 sp=0xc20801be48
gopkg.in/qml%2ev1._Cfunc_applicationExec(0x415b380)
    gopkg.in/qml.v1/_obj/_cgo_defun.c:71 +0x33 fp=0xc20801bea8 sp=0xc20801be90
gopkg.in/qml%2ev1.Run(0x41b0208, 0x0, 0x0)
    /Users/cookieo9/local/go-ext/src/gopkg.in/qml.v1/bridge.go:61 +0x1ba fp=0xc20801bf08 sp=0xc20801bea8
main.main()
    /Users/cookieo9/bad-qml.go:11 +0x29 fp=0xc20801bf40 sp=0xc20801bf08
runtime.main()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:259 +0x137 fp=0xc20801bfa8 sp=0xc20801bf40
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc20801bfb0 sp=0xc20801bfa8

goroutine 2 [syscall]:
runtime.notetsleepg(0xc20801df70, 0xdf8475800)
    /Users/cookieo9/local/go/src/pkg/runtime/lock_sema.c:273 +0x88 fp=0xc20801df48 sp=0xc20801df18
runtime.MHeap_Scavenger()
    /Users/cookieo9/local/go/src/pkg/runtime/mheap.c:668 +0x99 fp=0xc20801dfa8 sp=0xc20801df48
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc20801dfb0 sp=0xc20801dfa8
created by runtime.main
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:219

goroutine 3 [GC sweep wait]:
runtime.park(0x40700b0, 0x4243b58, 0x4235fdb, 0xd)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1421 +0xa7 fp=0xc208019f50 sp=0xc208019f40
runtime.parkunlock(0x4243b58, 0x4235fdb, 0xd)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1437 +0x47 fp=0xc208019f78 sp=0xc208019f50
bgsweep()
    /Users/cookieo9/local/go/src/pkg/runtime/mgc0.c:1114 +0xd2 fp=0xc208019fa8 sp=0xc208019f78
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc208019fb0 sp=0xc208019fa8
created by runtime.gc
    /Users/cookieo9/local/go/src/pkg/runtime/mgc0.c:1332

goroutine 4 [finalizer wait]:
runtime.park(0x40700b0, 0x4243b40, 0x4236134, 0xe)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1421 +0xa7 fp=0xc208039f08 sp=0xc208039ef8
runtime.parkunlock(0x4243b40, 0x4236134, 0xe)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1437 +0x47 fp=0xc208039f30 sp=0xc208039f08
runfinq()
    /Users/cookieo9/local/go/src/pkg/runtime/mgc0.c:1667 +0xf4 fp=0xc208039fa8 sp=0xc208039f30
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc208039fb0 sp=0xc208039fa8
created by runtime.gc
    /Users/cookieo9/local/go/src/pkg/runtime/mgc0.c:1332

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc208036fb0 sp=0xc208036fa8

goroutine 5 [semacquire]:
runtime.park(0x40700b0, 0x424b940, 0x4232a60, 0xa)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1421 +0xa7 fp=0xc208017de0 sp=0xc208017dd0
runtime.parkunlock(0x424b940, 0x4232a60, 0xa)
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1437 +0x47 fp=0xc208017e08 sp=0xc208017de0
runtime.semacquire(0xc20800c35c, 0x408e901)
    /Users/cookieo9/local/go/src/pkg/runtime/sema.goc:140 +0x131 fp=0xc208017e78 sp=0xc208017e08
sync.runtime_Semacquire(0xc20800c35c)
    /Users/cookieo9/local/go/src/pkg/runtime/sema.goc:199 +0x30 fp=0xc208017e90 sp=0xc208017e78
sync.(*Mutex).Lock(0xc20800c358)
    /Users/cookieo9/local/go/src/pkg/sync/mutex.go:66 +0xd2 fp=0xc208017eb8 sp=0xc208017e90
gopkg.in/qml%2ev1.(*Window).Wait(0xc20800c380)
    /Users/cookieo9/local/go-ext/src/gopkg.in/qml.v1/qml.go:868 +0xa6 fp=0xc208017ee0 sp=0xc208017eb8
main.run(0x0, 0x0)
    /Users/cookieo9/bad-qml.go:47 +0x171 fp=0xc208017f68 sp=0xc208017ee0
gopkg.in/qml%2ev1.func·002()
    /Users/cookieo9/local/go-ext/src/gopkg.in/qml.v1/bridge.go:58 +0x48 fp=0xc208017fa8 sp=0xc208017f68
runtime.goexit()
    /Users/cookieo9/local/go/src/pkg/runtime/proc.c:1490 fp=0xc208017fb0 sp=0xc208017fa8
created by gopkg.in/qml%2ev1.Run
    /Users/cookieo9/local/go-ext/src/gopkg.in/qml.v1/bridge.go:60 +0x1b3

rax     0xe
rbx     0x42446a0
rcx     0xb0093de8
rdx     0xffffffffffffffff
rdi     0x1903
rsi     0x0
rbp     0x4244620
rsp     0xb0093de8
r8      0xb0093e28
r9      0x4e73a53
r10     0x0
r11     0x286
r12     0x760a8a757bbb
r13     0x2caad639947a0
r14     0x138d0805b288c600
r15     0x4052380
rip     0x407fe4b
rflags  0x286
cs      0x7
fs      0x0
gs      0x0
exit status 2
niemeyer commented 9 years ago

That looks like an instance of http://golang.org/issue/7227

cookieo9 commented 9 years ago

Probably, although it's a little odd how the behaviour is different between calling exec in the event handler directly and calling it from a separate go-routine. I guess the Go->C->Go nature of the code contributes to that.

I can confirm that the issue isn't exec directly, as you can see the echo command printed out correctly, it's the SIGCHLD the program receives when the exec finishes which causes the problem. I took a regular qml program and sent it a SIGCHLD via "kill -CHLD" and it got stuck as well.

cookieo9 commented 9 years ago

It might be a good idea to list the caveat somewhere in the QML documentation.

eg: On darwin (OSX), if the qml program receives a SIGCHLD signal it will cause problems. This means that starting another executable will cause the QML app to crash or hang when the child process terminates.

niemeyer commented 9 years ago

I'll close this and reopen #26, which has more details on the issue.