digitalocean/go-qemu

qmp: goroutine leak in SocketMonitor

nathanpotter opened this issue · 1 comments

I have a program that connects directly to the qemu monitor, runs several commands, then closes the connection. After getting a goroutine stack of the program, there appears to be a goroutine leak when the SocketMonitor.listen goroutine encounters an error from the scanner, typically a use of closed network connection error after Disconnect. It tries to send a streamResponse through the channel with no listeners on the other side, and is then leaked.

Here's a trace of the leaked goroutine's stack:

go.coder.com/hypercon/vendor/github.com/digitalocean/go-qemu/qmp.(*SocketMonitor).listen(0xc424231b80, 0x7f1a511756e8, 0xc4201e5810, 0xc49b20baa0, 0xc49b20bb00)
	/home/npotter/go/src/go.coder.com/hypercon/vendor/github.com/digitalocean/go-qemu/qmp/socket.go:188 +0x2d2
created by go.coder.com/hypercon/vendor/github.com/digitalocean/go-qemu/qmp.(*SocketMonitor).Connect
	/home/npotter/go/src/go.coder.com/hypercon/vendor/github.com/digitalocean/go-qemu/qmp/socket.go:141 +0x315```

Fixed by #184