From da95342c24a71f81fefda055d7256b3d5dbb6b87 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 5 Jul 2021 09:40:32 +0100 Subject: [PATCH] Ensure worker has work before starting goroutine --- federationapi/routing/send.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index 978eafd4d..7c2576ab6 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -313,9 +313,6 @@ func (t *txnReq) processTransaction(ctx context.Context) (*gomatrixserverlib.Res input: newSendFIFOQueue(), }) worker := v.(*inputWorker) - if !worker.running.Load() { - go worker.run() - } wg.Add(1) task := &inputTask{ ctx: ctx, @@ -325,6 +322,9 @@ func (t *txnReq) processTransaction(ctx context.Context) (*gomatrixserverlib.Res } tasks = append(tasks, task) worker.input.push(task) + if !worker.running.CAS(false, true) { + go worker.run() + } } go func() { @@ -351,9 +351,6 @@ func (t *txnReq) processTransaction(ctx context.Context) (*gomatrixserverlib.Res } func (t *inputWorker) run() { - if !t.running.CAS(false, true) { - return - } defer t.running.Store(false) for { task, ok := t.input.pop()