Skip to content

Commit 09630e7

Browse files
drains channel on disconnect
1 parent 62007dc commit 09630e7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

qemu/domain.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ func (d *Domain) Events() (chan qmp.Event, chan struct{}, error) {
372372
// handle disconnection
373373
go func() {
374374
<-done
375+
// drain anything that gets sent on the channel
376+
// because the disconnect won't be processed if the
377+
// listenAndServe loop is waiting for the listener
378+
// to read from the unbuffered channel.
379+
go func() {
380+
for range stream {
381+
}
382+
}()
375383
d.disconnect <- stream
376384
close(stream)
377385
close(done)

qemu/domain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ func TestEvents(t *testing.T) {
578578
}
579579

580580
// Test when a listener connects, but disconnects without
581-
// receiving from the events chaannel returned.
581+
// receiving from the events channel returned.
582582
func TestEventsDerelictListener(t *testing.T) {
583583
d, done := testDomain(t, nil)
584584
defer done()

0 commit comments

Comments
 (0)