From 444e6c46fb342232f6914975b22a549c38e8f8b3 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Fri, 14 Jan 2022 09:17:13 -0600 Subject: [PATCH] Fix race condition when closing agent after gather A data race would occur where the context cancel would be called and overwritten at the same time. --- agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent.go b/agent.go index 4a3621c..effe86d 100644 --- a/agent.go +++ b/agent.go @@ -893,10 +893,10 @@ func (a *Agent) Close() error { done := make(chan struct{}) a.afterRun(func(context.Context) { + a.gatherCandidateCancel() close(done) }) - a.gatherCandidateCancel() a.err.Store(ErrClosed) a.tcpMux.RemoveConnByUfrag(a.localUfrag)