Skip to content

Bug report: FHIRModels is not concurrency safe, leading to crashes at runtime #36

@lukaskollmer

Description

@lukaskollmer

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions