You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Not threadsafe (or possibly even async-safe) on Julia 1.10 #146
For julia 1.11+, the list of active patches (the patch env) is stored in a ScopedValue, which makes it safe to apply inside tasks, even when those tasks are scheduled on different threads and executing concurrently. For earlier versions, the patch env is stored in a package global Ref, which is definitely not concurrency friendly lol.
It seems really bad to me that there's silently, inconsistently thread-unsafe application of patches in some versions of julia but not others. I'd rather we allow users to opt out of using the ScopedValues fallback if they need to. I think it would be possible to allow users to control whether a global ref is used or a scoped value with a configuration option, like a boolean flag ref that can be set.
The original thinking on this was to let newer versions of Julia use the newer features. However, inconsistent behavior between different versions of Julia is asking for trouble. I see two ways out of this mess:
Release new versions of Mocking.jl which require newer versions of Julia for the features that require it. I want to keep supporting the LTS so I think I would end up supporting a version for the LTS, 1.11+ (ScopedValues support), and 1.12+ (ability to drop @mock on call sites).
Introduce a "strategy" global which allows the user to choose between the Ref approach, ScopedValues, or ScopedValues without @mock). If the user attempts to use a strategy which isn't supported by that version of Julia we can throw an error. The main issue with this would be maintainability of the code base.
I think option 2 would be better if we can support it.
There is also a challenge with what to do with the current inconsistent behavior. With option 2 I think I'd have a "inconsistent" strategy which keeps the current behavior as the default. I could also make a new breaking release which possible uses the best strategy and forces users to opt into another strategy if they want to use that version of Julia with Mocking.
Activity
omus commentedon Sep 4, 2026
The original thinking on this was to let newer versions of Julia use the newer features. However, inconsistent behavior between different versions of Julia is asking for trouble. I see two ways out of this mess:
@mockon call sites).@mock). If the user attempts to use a strategy which isn't supported by that version of Julia we can throw an error. The main issue with this would be maintainability of the code base.I think option 2 would be better if we can support it.
There is also a challenge with what to do with the current inconsistent behavior. With option 2 I think I'd have a "inconsistent" strategy which keeps the current behavior as the default. I could also make a new breaking release which possible uses the best strategy and forces users to opt into another strategy if they want to use that version of Julia with Mocking.