Skip to content

Commit

Permalink
add atomic closed
Browse files Browse the repository at this point in the history
Signed-off-by: Filinto Duran <[email protected]>
  • Loading branch information
filintod committed Jul 31, 2023
1 parent 4b671d1 commit 8339f51
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion state/hashicorp/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"net/http"
"reflect"
"sync/atomic"

"github.com/hashicorp/consul/api"
"github.com/hashicorp/go-cleanhttp"
Expand All @@ -37,6 +38,7 @@ type Consul struct {
keyPrefixPath string
logger logger.Logger
transport *http.Transport
closed atomic.Bool
}

type consulConfig struct {
Expand Down Expand Up @@ -171,7 +173,7 @@ func (c *Consul) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
}

func (c *Consul) Close() error {
if c != nil && c.transport != nil {
if c.closed.CompareAndSwap(false, true) && c.transport != nil {
c.transport.CloseIdleConnections()
}
return nil
Expand Down

0 comments on commit 8339f51

Please sign in to comment.