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
Bug report: FHIRModels is not concurrency safe, leading to crashes at runtime #36
Note: I'm not asking that the library be upgraded to Swift 6, or that all the types be made Sendable. I know why they aren't.
The specific issue here is that in FHIRDateComponents, there is a static var calendar = Calendar(identifier: .gregorian), which seems to be used only by some of the static methods on the type.
we observe regular crashes in our codebase, when attempting to have multiple threads perform (independent!) operations that use the FHIRModels types (some of which in turn internally use the FHIRDateComponents, which then cause a crash, presumably due to the concurrent accesses to the global mutable variable)
since creating Calendars isn't overly expensive, IMO, these static functions should simply obtain a temporary Calendar object and use that, instead of having a global variable.
(unless there was a specific reason for not implementing it this way in the first place, though even then there probably exists a better solution than the current approach.)
Thanks for the report. We need to audit the library for Swift Concurrency; static vars are indeed one of the classic causes of issues in this new world.
@p2-apple do you have a (rough) estimate when this will be fixed? we keep running into this issue, and it keeps causing crashes in our codebase.
i feel like it should be feasible to have a small release that addresses only this bug, rather than keeping it around until the entire library is audited for concurrency.
(also, and i might be wrong on this, but given the fact that (I) none of the FHIR types can be made Sendable anyway and (II) apart from this calendar variable there is no other global mutable state in the library, this probably is the only major concurrency issue anyway)
Thanks, I can reproduce the crash in the testAllParsing() unit tests. Adding the FHIRDateComponents.dateComponents(...) call into 100 queue.async block. Not however when I use a TaskGroup. Fix incoming.
Activity
convert more tests to Swift Testing, work around apple/FHIRModels#36
PSchmiedmayer commentedon Apr 26, 2025
Thank you for reporting this here @lukaskollmer 🚀
p2-apple commentedon Apr 26, 2025
Thanks for the report. We need to audit the library for Swift Concurrency; static vars are indeed one of the classic causes of issues in this new world.
lukaskollmer commentedon May 14, 2025
@p2-apple do you have a (rough) estimate when this will be fixed? we keep running into this issue, and it keeps causing crashes in our codebase.
i feel like it should be feasible to have a small release that addresses only this bug, rather than keeping it around until the entire library is audited for concurrency.
(also, and i might be wrong on this, but given the fact that (I) none of the FHIR types can be made Sendable anyway and (II) apart from this
calendarvariable there is no other global mutable state in the library, this probably is the only major concurrency issue anyway)p2-apple commentedon May 14, 2025
Let me try to get to this this week
p2-apple commentedon May 14, 2025
Thanks, I can reproduce the crash in the
testAllParsing()unit tests. Adding theFHIRDateComponents.dateComponents(...)call into 100queue.asyncblock. Not however when I use aTaskGroup. Fix incoming.Fixes & Improvements, bump to 0.7
Update to FHIRModels 0.9 (#4)