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

Commit 0ce977e

Browse files
authored
Merge pull request #681 from teawater/fixVmContextloopcrash
VmContext.loop: Hold ctx.lock when access ctx.handler to fix crash
2 parents 971eed2 + 48dcf87 commit 0ce977e

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)