aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-11-17 23:50:02 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-11-17 23:50:02 +0900
commit866270ff05379c571c665940a7c1b2010891e960 (patch)
treeb01ff4e01b984ce9a080478ce8b8efd6c71a94b5
parentc1fad649e8410a088793e952fcffa7a7df552d2d (diff)
fmsg: add to wg prior to enqueue
Adding after channel write is racy. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
-rw-r--r--internal/fmsg/defer.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/internal/fmsg/defer.go b/internal/fmsg/defer.go
index 0f3f5ad5..0161e27e 100644
--- a/internal/fmsg/defer.go
+++ b/internal/fmsg/defer.go
@@ -33,16 +33,17 @@ func dequeue() {
// queue submits ops to msgbuf but drops messages
// when the buffer is full and dequeue is withholding
func queue(op dOp) {
+ queueSync.Add(1)
+
select {
case msgbuf <- op:
- queueSync.Add(1)
default:
// send the op anyway if not withholding
// as dequeue will get to it eventually
if !wstate.Load() {
- queueSync.Add(1)
msgbuf <- op
} else {
+ queueSync.Done()
// increment dropped message count
dropped.Add(1)
}