Docs suggestion: call out actor-reentrancy pitfall in the "caching a Worker" migration guide
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- swift
- Domain
- documentation
Research direction
Start with runtimes/apple/migrating-from-legacy.mdx, especially the linked lines in the “Caching a Rive File / Worker” guide. Explain that caching a Worker behind an actor can still construct it twice when initialization suspends, and document the in-flight Task approach shown in the issue. Done means the migration guide clearly calls out the reentrancy pitfall and its suggested mitigation.
Written by the indexing model from the issue text.
Description
Summary
The Caching a Rive File / Worker guide recommends lazily creating and caching a single Worker behind an actor
This pattern is a check-then-await-then-write sequence. Because await Worker() is a suspension point, two callers racing worker() can both observe cachedWorker == nil before either has written the result, leading to Worker() being constructed twice (wasted init cost, and briefly two live Worker/CommandServer instances). actor/@MainActor isolation prevents data races here, but not this logic race (reentrancy across an await), so neither the compiler nor Thread Sanitizer catches it.
We ran into exactly this in our app and ended up caching the in-flight Task instead of the value:
actor WorkerProvider {
@MainActor private var cachedWorker: Worker?
@MainActor private var loadingTask: Task<Void, Error>?
@MainActor
func worker() async throws -> Worker {
if let cachedWorker { return cachedWorker }
let task = loadingTask ?? Task {
cachedWorker = try await Worker()
}
loadingTask = task
try await task.value
return cachedWorker!
}
}
- Dominant language
- MDX
- Stars
- 30
- Forks
- 56
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 48
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rive-app/rive-docs
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
-
good first issue
rive-app/rive-docs#725 · 6 comments · 1 reaction · 1 assignee ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
good first issue
All issues in rive-app/rive-docs
Similar issues
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fullcalendar/fullcalendar#8106 ·