-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Julia 1.11 "Multiple concurrent writes to Dict detected!" middleware_cache #226
Comments
It's probably fine to have a cache per task, so https://docs.julialang.org/en/v1/base/parallel/#Base.task_local_storage-Tuple{Any} could help here. The cache is probably read heavy, so it may be slightly more efficient to add a multiple reader/single writer lock and have the cache be centralized. However, it's only better if acquiring a read lock is really cheap. This implementation https://juliaconcurrent.github.io/ConcurrentUtils.jl/dev/#ConcurrentUtils.ReadWriteLock appears correct. Probably it's better to stick with the 1st option to avoid complexity. |
Hi @arlowhite, Thanks for the error logs and description. In your code you're hitting the same route multiple times before the cache is populated. In this scenario multiple threads are trying to write to the same location in cache at the same time. This "middleware_cache" stores the fully composed middleware chain for each route - so we don't have to recompute it for each request. Normally I wouldn't argue for using locks - which can introduce a decent amount of overhead, but in this case I think it would be fine to use a reentrant lock to protect the writes to this dictionary since the writes only happens once for each route. @frankier , |
After updating to Julia 1.11.0 I've started to see this error. I never saw it with Julia 1.10.5
Oxygen v1.5.13
.julia\packages\Oxygen\RkoDD\src\middleware.jl:61
middleware_cache[key] = strategy
I don't see it once the Julia session is warmed-up (if I restart server in same REPL session). But it happens every time during the first server start in a fresh Julia session. I'm hitting the server with multiple requests simultaneously. Running in parallel mode,
-t auto,1
Let me know if you need more information.
Impact
The request encountering this error will get a HTTP 500 response
The text was updated successfully, but these errors were encountered: