This repository was archived by the owner on Jul 18, 2025. It is now read-only.
Commit 52506c8
committed
Load schemas in init()
Issue Observed
--------------
When multiple goroutines uses different `Project` instances concurrently,
Go's race detector complains data races.
Issue Detail
------------
`schema_helpers.go` have some global variables and they are initialized
by `setupSchemaLoaders()` when `validate()` and other schema functions
are called for the first time.
However, `setupSchemaLoaders()` does not have mutex, so some times
multiple gorutines proceed into this function, then a race happens.
Suggested Resolution
--------------------
We can add a mutex to `setupSchemaLoader()` to avoid the race condition.
However, the function is supposed to cache results and called not so
many times. Therefore, in this patch, we simply initialize schemas in
`init()`.
Signed-off-by: Iwasaki Yudai <yudai@arielworks.com>1 parent 8e4221d commit 52506c8
2 files changed
+10
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
20 | 30 | | |
21 | 31 | | |
22 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | 160 | | |
165 | 161 | | |
166 | 162 | | |
| |||
174 | 170 | | |
175 | 171 | | |
176 | 172 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | 173 | | |
182 | 174 | | |
183 | 175 | | |
| |||
250 | 242 | | |
251 | 243 | | |
252 | 244 | | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | 245 | | |
258 | 246 | | |
259 | 247 | | |
| |||
289 | 277 | | |
290 | 278 | | |
291 | 279 | | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | 280 | | |
297 | 281 | | |
298 | 282 | | |
| |||
0 commit comments