skiptools / skiptools/skip

`#SendingRisksDataRace` errors calling async transpiled bridged `@MainActor` methods in a `Task`

Open
#657 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

fuse
Dominant language
Swift
Stars
3.2k
Forks
106
Avg merge
6d 13h
Merged PRs (30d)
1

Description

Skip Fuse gets #SendingRisksDataRace errors calling async transpiled bridged methods in a Task. (The bridge isn't @MainActor or Sendable.)

/Users/dfabulich/git/skiphack/skipapp-showcase-fuse/Sources/ShowcaseFuse/WebAuthenticationSessionPlayground.swift:89:71: error: sending 'self.webAuthenticationSession' risks causing data races [#SendingRisksDataRace]
 87 |                 let urlWithToken: URL
 88 |                 if #available(iOS 17.4, *) {
 89 |                     urlWithToken = try await webAuthenticationSession.authenticate(
    |                                                                       |- error: sending 'self.webAuthenticationSession' risks causing data races [#SendingRisksDataRace]
    |                                                                       `- note: sending main actor-isolated 'self.webAuthenticationSession' to nonisolated instance method 'authenticate(using:callback:preferredBrowserSession:additionalHeaderFields:)' risks causing data races between nonisolated and main actor-isolated uses
 90 |                         using: URL(string: "https://push.skip.tools/webauth-demo/?scheme=org.appfair.app.showcase")!,
 91 |                         callback: .customScheme("org.appfair.app.showcase"),

/Users/dfabulich/git/skiphack/skipapp-showcase-fuse/Sources/ShowcaseFuse/WebAuthenticationSessionPlayground.swift:96:71: error: sending 'self.webAuthenticationSession' risks causing data races [#SendingRisksDataRace]
 94 |                     )
 95 |                 } else {
 96 |                     urlWithToken = try await webAuthenticationSession.authenticate(
    |                                                                       |- error: sending 'self.webAuthenticationSession' risks causing data races [#SendingRisksDataRace]
    |                                                                       `- note: sending main actor-isolated 'self.webAuthenticationSession' to nonisolated instance method 'authenticate(using:callbackURLScheme:preferredBrowserSession:)' risks causing data races between nonisolated and main actor-isolated uses
 97 |                         using: URL(string: "https://push.skip.tools/webauth-demo/?scheme=org.appfair.app.showcase")!,
 98 |                         callbackURLScheme: "org.appfair.app.showcase",

[#SendingRisksDataRace]: <https://docs.swift.org/compiler/documentation/diagnostics/sending-risks-data-race>

The workaround I used was to add a Sendable extension in an #if SKIP_BRIDGE block.

extension WebAuthenticationSession: @unchecked Sendable {}

… but that adds a warning to the build, "warning: When bridging API from a transpiled module, place all code within a #if !SKIP_BRIDGE condition"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported async transpiled bridge calls to @MainActor methods in the Skip Fuse WebAuthenticationSessionPlayground.swift example and review how Skip handles bridged actor isolation and Sendable annotations. Reproduce the #SendingRisksDataRace diagnostics, then verify that the supported bridge output avoids the diagnostic without requiring an unchecked Sendable extension or producing the SKIP_BRIDGE warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
compilers, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.