Skip to content

Sendable issue on Linux #34

@0xTim

Description

@0xTim

So I'm not sure the best way forward for this one - but summary:

We're using the OAuthentication library as part of a package that's consumed by multiple apps and multiple platforms (Apple and Linux). We're having an issue using the package when compiling on Linux with the following code:

let config = Authenticator.Configuration(
    appCredentials: appCredentials,
    loginStorage: loginStorage,
    tokenHandling: tokenHandling,
    userAuthenticator: userAuthenticator,
    authenticationStatusHandler: authenticationStatusHandler
)

let authenticator = Authenticator(config: config)

That produces the error:

error: sending 'config' risks causing data races [#SendingRisksDataRace]
338 |         )
339 | 
340 |         let authenticator = Authenticator(config: config)
    |                             |- error: sending 'config' risks causing data races [#SendingRisksDataRace]
    |                             `- note: sending 'config' to actor-isolated initializer 'init(config:urlLoader:)' risks causing data races between actor-isolated and local nonisolated uses

Now the error makes sense, since Configuration is not Sendable and the status handler makes it awkward to be safe. I'm not sure why this compiles fine on macOS, I feel like I'm missing an isolation trick somewhere.

The workaround I've come up with so far is to make Configuration Sendable, but that can require handling the status with some kind of lock/mutex. It's definitely workable (and makes it safe) but can be difficult to use.

Do you have any insight as to why this is failing on Linux to start? I'm happy to submit a patch too

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