[BUG] Swift access race when run with Thread sanitizer
General information
Superwallversion: 3.2.2- iOS version(s): 17.0
- CocoaPods/Carthage version (if applicable):
- Xcode version: Version 14.3.1 (14E300c)
- Devices/Simulators affected: iPhone simulator
- Reproducible in the demo project? (Yes/No): Yes
- Related issues:
Describe the bug
When I turn on Thread sanitizer in a scheme, and run the app, the following warning appears:
/Users/.../Library/Developer/Xcode/DerivedData/Weathergraph-eksxezdcznqhaibhzaurdwsgkvku/SourcePackages/checkouts/Superwall-iOS/Sources/SuperwallKit/Dependencies/DependencyContainer.swift:272 Swift access race in SuperwallKit.Superwall.$subscriptionStatus.getter : Combine.Published<SuperwallKit.SubscriptionStatus>.Publisher at 0x1246653c0
Steps to reproduce
Run an app with SuperwallKit with thread sanitizer.
Hey, someone else also mentioned this but I'm yet to reproduce it. You said you managed to reproduce it our example apps? How did you do that? I tried with the thread sanitiser but nothing happened. Any more details of how to reproduce this would help a lot!
I'm closing this because I've been unable to reproduce this. If it still happens, let me know and I'll reopen the issue.
I'm closing this because I've been unable to reproduce this. If it still happens, let me know and I'll reopen the issue.
It still happens. Reproduced on 4.16.1, deterministically — 3/3 runs. Flagging it here as invited rather than opening a duplicate; happy to file fresh if you'd prefer.
It's the same line, not a lookalike
The original report cited DependencyContainer.swift:272 on 3.2.2. That line was:
subscriptionStatus: subscriptionStatus ?? Superwall.shared.$subscriptionStatus.eraseToAnyPublisher(),
The same statement in 4.16.1 is DependencyContainer.swift:405, in the same makePresentationRequest:
subscriptionStatus: Superwall.shared.$subscriptionStatus.eraseToAnyPublisher(),
Same property, same function, same projected-value access — only the line number moved and the optional override parameter went away.
Environment
- SuperwallKit 4.16.1 (SPM)
- Xcode 26.4.1 (17E202)
- iPhone 17 Pro simulator, iOS 26.4.1 (23E254a)
- Plain SwiftUI app, default
SuperwallOptions, noPurchaseController
Steps to reproduce
Superwall.configure(apiKey:)at launch.- Call
await Superwall.shared.getPresentationResult(forPlacement: "anything"). The placement doesn't need to exist in a campaign. - Build with
-enableThreadSanitizer YESand run.
TSan reports within ~20 seconds of launch. No app-side concurrency, no threading tricks — one public API call.
Trace
WARNING: ThreadSanitizer: Swift access race
Modifying access of Swift variable at 0x000335e27fc0 by thread T9:
#0 Superwall.$subscriptionStatus.getter Superwall.swift
#1 DependencyContainer.makePresentationRequest(...) DependencyContainer.swift:405
#2 Superwall.internallyGetPresentationResult(forPlacement:requestType:)
PublicGetPresentationResult.swift:97
Previous modifying access of Swift variable at 0x000335e27fc0 by main thread:
#0 Superwall.$subscriptionStatus.getter Superwall.swift
#1 DependencyContainer.makePresentationRequest(...) DependencyContainer.swift:405
#2 Superwall.internallyHandleImplicitTrigger(forPlacement:withData:)
Tracking.swift:112
Location is heap block of size 112 allocated by main thread:
#2 Superwall.__allocating_init(...) Superwall.swift:467
#3 static Superwall.configure(...) Superwall.swift:695
Thread T9 (tid=1369566, running) is a GCD worker thread
SUMMARY: ThreadSanitizer: Swift access race Superwall.swift in Superwall.$subscriptionStatus.getter
What's happening
Both sides of the race are inside the SDK, at the same line, reached by two different internal paths:
internallyGetPresentationResult→makePresentationRequeston a background executorinternallyHandleImplicitTrigger→makePresentationRequeston the main thread
Reading the projected value of a @Published property is a modifying access under Swift's exclusivity rules, so two concurrent reads violate it even though neither side assigns. Since the app never touches $subscriptionStatus itself, an integrator can't avoid this from the outside — which may be why the original reporter couldn't narrow it down beyond "run with Thread Sanitizer".
That the implicit-trigger path fires on its own is probably also why it looked flaky: it depends on the SDK's own event traffic overlapping a presentation-result call, rather than on anything the app does.
I'm happy to share the harness app, or to test a patch — the reproduction is deterministic on my machine.