Skip to content

Commit 294bfc6

Browse files
authored
Merge pull request #482 from jfontan/fix/race-condition-getting-uasts
function: fix race condition getting UASTs
2 parents e080a71 + 2a84bdf commit 294bfc6

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

internal/function/uast.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"strconv"
99
"strings"
10+
"sync"
1011

1112
lru "github.com/hashicorp/golang-lru"
1213
bblfsh "gopkg.in/bblfsh/client-go.v2"
@@ -53,6 +54,7 @@ type uastFunc struct {
5354
XPath sql.Expression
5455

5556
h hash.Hash
57+
m sync.Mutex
5658
}
5759

5860
// IsNullable implements the Expression interface.
@@ -113,11 +115,13 @@ func (u *uastFunc) TransformUp(fn sql.TransformExprFunc) (sql.Expression, error)
113115
}
114116
}
115117

116-
tu := *u
117-
tu.Mode = mode
118-
tu.Blob = blob
119-
tu.Lang = lang
120-
tu.XPath = xpath
118+
tu := uastFunc{
119+
Mode: mode,
120+
Blob: blob,
121+
Lang: lang,
122+
XPath: xpath,
123+
h: sha1.New(),
124+
}
121125

122126
return fn(&tu)
123127
}
@@ -195,7 +199,10 @@ func (u *uastFunc) getUAST(
195199
lang, xpath string,
196200
mode bblfsh.Mode,
197201
) (interface{}, error) {
202+
u.m.Lock()
198203
key, err := computeKey(u.h, mode.String(), lang, blob)
204+
u.m.Unlock()
205+
199206
if err != nil {
200207
return nil, err
201208
}

0 commit comments

Comments
 (0)