From 04d1b2d83c68e830d396fb34a0e2d49b312b4798 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Fri, 25 Mar 2022 09:16:25 +0100 Subject: [PATCH] avoid race condition Signed-off-by: Florian Lehner --- nfqueue.go | 4 ++-- nfqueue_linux_integration_test.go | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/nfqueue.go b/nfqueue.go index 2f116a8..86eb0cd 100644 --- a/nfqueue.go +++ b/nfqueue.go @@ -151,10 +151,10 @@ func (nfqueue *Nfqueue) RegisterWithErrorFunc(ctx context.Context, fn HookFunc, return err } + nfqueue.wg.Add(1) go func() { - nfqueue.wg.Add(1) + defer nfqueue.wg.Done() nfqueue.socketCallback(ctx, fn, errfn, seq) - nfqueue.wg.Done() }() return nil diff --git a/nfqueue_linux_integration_test.go b/nfqueue_linux_integration_test.go index 69cd565..14ea6dc 100644 --- a/nfqueue_linux_integration_test.go +++ b/nfqueue_linux_integration_test.go @@ -98,5 +98,4 @@ func TestTimeout(t *testing.T) { // Block till the context expires <-ctx.Done() - }