Skip to content

Commit dd98481

Browse files
committed
Fix channel message delay
This commit fixes an issue where a new channel message isn't sent right away. Rather it would wait in the queue until another next message is queued. This issue wasn't common and likely would be difficult to discover on a busy production machine. But occasionally popped up in a failed test. See #763
1 parent e40a665 commit dd98481

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

internal/server/pubsub.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,24 +327,22 @@ func (s *Server) liveSubscription(
327327
go func() {
328328
log.Debugf("pubsub open")
329329
defer log.Debugf("pubsub closed")
330+
target.cond.L.Lock()
331+
defer target.cond.L.Unlock()
330332
for {
331-
var msgs []submsg
332-
target.cond.L.Lock()
333-
if len(target.msgs) > 0 {
334-
msgs = target.msgs
333+
for len(target.msgs) > 0 {
334+
msgs := target.msgs
335335
target.msgs = nil
336+
target.cond.L.Unlock()
337+
for _, msg := range msgs {
338+
writeMessage(msg)
339+
}
340+
target.cond.L.Lock()
336341
}
337-
target.cond.L.Unlock()
338-
for _, msg := range msgs {
339-
writeMessage(msg)
340-
}
341-
target.cond.L.Lock()
342342
if target.closed {
343-
target.cond.L.Unlock()
344-
return
343+
break
345344
}
346345
target.cond.Wait()
347-
target.cond.L.Unlock()
348346
}
349347
}()
350348

0 commit comments

Comments
 (0)