Commit 7c41a4c3ed0874ac24e53b7fd3aae69e099b53e4
1 parent
437859ae90
Exists in
master
and in
1 other branch
added mutex lock for allPayloads
Showing
1 changed file
with
7 additions
and
0 deletions
Show diff stats
json_utility.go
1 | +// @TODO: Be more verbose about corrupt config error. | |
2 | +// Do the same errror checking when doing table reloading. | |
3 | +// Discard previous tables when doing reload. | |
1 | 4 | package restutility |
2 | 5 | |
3 | 6 | import ( |
... | ... | @@ -7,8 +10,10 @@ import ( |
7 | 10 | "gopkg.in/rana/ora.v3" |
8 | 11 | "io" |
9 | 12 | "io/ioutil" |
13 | + "sync" | |
10 | 14 | ) |
11 | 15 | |
16 | +var mu = &sync.Mutex{} | |
12 | 17 | var allPayloads []payloadBuff |
13 | 18 | |
14 | 19 | type LangMap map[string]map[string]string |
... | ... | @@ -134,6 +139,8 @@ func loadCorrelations(id string) []CorrelationField { |
134 | 139 | |
135 | 140 | func InitTables(db *ora.Ses, project string) error { |
136 | 141 | jsonbuf, _ := fetchJSON(db, EqualQuotes(project)) |
142 | + mu.Lock() | |
143 | + defer mu.Unlock() | |
137 | 144 | json.Unmarshal(jsonbuf, &allPayloads) |
138 | 145 | if len(allPayloads) == 0 { |
139 | 146 | return errors.New("tables config is corrupt") | ... | ... |