Skip to content

Commit

Permalink
add mutex lock to prevent race condition in exec() function (#834)
Browse files Browse the repository at this point in the history
defer mutex unlock
  • Loading branch information
sfc-gh-ext-simba-lb committed Jun 27, 2023
1 parent 663cccc commit ee57d93
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type snowflakeConn struct {
var (
queryIDPattern = `[\w\-_]+`
queryIDRegexp = regexp.MustCompile(queryIDPattern)
errMutex = &sync.Mutex{}
)

func (sc *snowflakeConn) exec(
Expand Down Expand Up @@ -138,7 +139,10 @@ func (sc *snowflakeConn) exec(
}
logger.WithContext(ctx).Infof("Success: %v, Code: %v", data.Success, code)
if !data.Success {
return nil, (populateErrorFields(code, data)).exceptionTelemetry(sc)
errMutex.Lock()
defer errMutex.Unlock()
err = (populateErrorFields(code, data)).exceptionTelemetry(sc)
return nil, err
}

// handle PUT/GET commands
Expand Down

0 comments on commit ee57d93

Please sign in to comment.