Commit cc28e95
authored
fix: don't drop canonicalized path by cache clear (#791)
`Canonicalized path was dropped` error started to happen when I started
to call `resolver.cache_clear()` frequently (so that I can clear the
cache for each resolution to support
vitest-dev/vitest#8754 (comment)).
My guess of the cause is:
- `resolver.cache_clear()` is called while a resolution is happening
- `self.paths` is cleared because of that call
- this `Arc::downgrade` removes the last strong reference:
https://github.com/oxc-project/oxc-resolver/blob/9de30883232082e425ae0c837c69adf07e8570e6/src/cache/cache_impl.rs#L283
- this `weak.upgrade()` errors:
https://github.com/oxc-project/oxc-resolver/blob/9de30883232082e425ae0c837c69adf07e8570e6/src/cache/cache_impl.rs#L288
This PR solves that by using `Mutex<Weak<_>>>` instead of
`OnceLock<Weak<_>>`. Since `weak.upgrade()` may return None, I changed
the code to resolve when `weak` returned None. The previous code assumed
that `weak.upgrade()` always returns a value and that allowed us to use
`OnceLock`.
I guess this will have a negative impact on perf...1 parent cbed279 commit cc28e95
2 files changed
+39
-53
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
249 | 242 | | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
| 243 | + | |
266 | 244 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
271 | 251 | | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
280 | 266 | | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
| 267 | + | |
| 268 | + | |
290 | 269 | | |
291 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
292 | 278 | | |
293 | 279 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
0 commit comments