From c32f17d14ef3e7e50b2d3d7f197a8e776f893bcb Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 6 Jul 2021 00:10:10 +0430 Subject: [PATCH 1/4] fix race condition on sudphConn for closing address_reslover --- pkg/snet/arclient/client.go | 3 +-- pkg/snet/network.go | 13 ++++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/pkg/snet/arclient/client.go b/pkg/snet/arclient/client.go index 360d4467d7..c51d02dd7c 100644 --- a/pkg/snet/arclient/client.go +++ b/pkg/snet/arclient/client.go @@ -432,10 +432,9 @@ func (c *httpClient) Close() error { if err := c.sudphConn.Close(); err != nil { c.log.WithError(err).Errorf("Failed to close SUDPH") } + close(c.closed) } - close(c.closed) - return nil } diff --git a/pkg/snet/network.go b/pkg/snet/network.go index 128e6b576f..e36b6018ba 100644 --- a/pkg/snet/network.go +++ b/pkg/snet/network.go @@ -274,16 +274,11 @@ func (n *Network) Close() error { if directClient == nil { continue } - wg.Add(1) - go func(client directtp.Client) { - err := client.Close() - if err != nil { - directErrors <- err - } - wg.Done() - }(directClient) + err := directClient.Close() + if err != nil { + directErrors <- err + } } - wg.Wait() close(directErrors) if dmsgErr != nil { From 04ba8495d93d4cc01a6103c25610d724d6fb01f2 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 6 Jul 2021 00:21:16 +0430 Subject: [PATCH 2/4] add wg.Wait() that deleted in wrong --- pkg/snet/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/snet/network.go b/pkg/snet/network.go index e36b6018ba..24162bc88c 100644 --- a/pkg/snet/network.go +++ b/pkg/snet/network.go @@ -280,7 +280,7 @@ func (n *Network) Close() error { } } close(directErrors) - + wg.Wait() if dmsgErr != nil { return dmsgErr } From c537b8dc095b334021d63071faf7320748d41ac3 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 6 Jul 2021 00:10:10 +0430 Subject: [PATCH 3/4] fix race condition on sudphConn for closing address_reslover --- pkg/snet/arclient/client.go | 3 +-- pkg/snet/network.go | 13 ++++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/pkg/snet/arclient/client.go b/pkg/snet/arclient/client.go index 360d4467d7..c51d02dd7c 100644 --- a/pkg/snet/arclient/client.go +++ b/pkg/snet/arclient/client.go @@ -432,10 +432,9 @@ func (c *httpClient) Close() error { if err := c.sudphConn.Close(); err != nil { c.log.WithError(err).Errorf("Failed to close SUDPH") } + close(c.closed) } - close(c.closed) - return nil } diff --git a/pkg/snet/network.go b/pkg/snet/network.go index 128e6b576f..e36b6018ba 100644 --- a/pkg/snet/network.go +++ b/pkg/snet/network.go @@ -274,16 +274,11 @@ func (n *Network) Close() error { if directClient == nil { continue } - wg.Add(1) - go func(client directtp.Client) { - err := client.Close() - if err != nil { - directErrors <- err - } - wg.Done() - }(directClient) + err := directClient.Close() + if err != nil { + directErrors <- err + } } - wg.Wait() close(directErrors) if dmsgErr != nil { From 83a904a1e267589162b5772c253eef952fcd7f69 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 6 Jul 2021 00:21:16 +0430 Subject: [PATCH 4/4] add wg.Wait() that deleted in wrong --- pkg/snet/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/snet/network.go b/pkg/snet/network.go index e36b6018ba..24162bc88c 100644 --- a/pkg/snet/network.go +++ b/pkg/snet/network.go @@ -280,7 +280,7 @@ func (n *Network) Close() error { } } close(directErrors) - + wg.Wait() if dmsgErr != nil { return dmsgErr }