Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 48dcf87

Browse files
committed
VmContext.loop: Hold ctx.lock when access ctx.handler to fix crash
Got following crash in hyperd: E0409 03:06:59.520358 30295 json.go:458] SB[vm-QctatzSfUb] tty socket closed, quit the the reading goroutine: read unix @->/var/run/hyper/vm-QctatzSfUb/tty.sock: use of closed panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x93c26a] goroutine 33274 [running]: github.com/hyperhq/hyperd/vendor/github.com/hyperhq/runv/hypervisor.(*VmContext).loop(0xc42171eb00) /root/gopath/src/github.com/hyperhq/hyperd/vendor/github.com/hyperhq/runv/hypervisor/hypervisor.go:24 +0x20a created by github.com/hyperhq/hyperd/vendor/github.com/hyperhq/runv/hypervisor.(*VmContext).Launch /root/gopath/src/github.com/hyperhq/hyperd/vendor/github.com/hyperhq/runv/hypervisor/hypervisor.go:92 The root cause is VmContext.loop access ctx.handler without lock. Add code hold ctx.lock to handle the issue. Signed-off-by: Hui Zhu <teawater@hyper.sh>
1 parent acc162c commit 48dcf87

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

hypervisor/hypervisor.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import (
1111
)
1212

1313
func (ctx *VmContext) loop() {
14-
for ctx.handler != nil {
14+
for {
15+
ctx.lock.Lock()
16+
handler := ctx.handler
17+
ctx.lock.Unlock()
18+
if handler == nil {
19+
break
20+
}
1521
ev, ok := <-ctx.Hub
1622
if !ok {
1723
ctx.Log(ERROR, "hub chan has already been closed")
@@ -21,7 +27,7 @@ func (ctx *VmContext) loop() {
2127
continue
2228
}
2329
ctx.Log(TRACE, "main event loop got message %d(%s)", ev.Event(), EventString(ev.Event()))
24-
ctx.handler(ctx, ev)
30+
handler(ctx, ev)
2531
}
2632

2733
// Unless the ctx.Hub channel is drained, processes sending operations can

0 commit comments

Comments
 (0)