Make dep client thread safe (#850)

Make dep client thread safe
This commit is contained in:
petitout
2022-12-19 12:27:59 -07:00
committed by GitHub
parent e0943fdcd7
commit 44a19bcb21

View File

@@ -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")