From 44a19bcb21f411b89a25ded1e9ffdf823f2d1039 Mon Sep 17 00:00:00 2001 From: petitout Date: Mon, 19 Dec 2022 12:27:59 -0700 Subject: [PATCH] Make dep client thread safe (#850) Make dep client thread safe --- dep/client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dep/client.go b/dep/client.go index 6b0eee39..417f90d8 100644 --- a/dep/client.go +++ b/dep/client.go @@ -8,6 +8,7 @@ import ( "net/url" "path" "strings" + "sync" "time" "github.com/garyburd/go-oauth/oauth" @@ -52,7 +53,8 @@ type Client struct { userAgent string client HTTPClient - baseURL *url.URL + baseURL *url.URL + sessionMutex sync.Mutex } type OAuthParameters struct { @@ -80,6 +82,9 @@ func NewClient(p OAuthParameters, opts ...Option) *Client { } func (c *Client) session() error { + // making sure the session creation is thread safe if the client is used amongst multiple go routine + c.sessionMutex.Lock() + defer c.sessionMutex.Unlock() if c.authSessionToken == "" { if err := c.newSession(); err != nil { return errors.Wrap(err, "creating new auth session for dep")