-
Notifications
You must be signed in to change notification settings - Fork 749
Description
Summary
We've been reproducing a hang where no new fetches are able to proceed due to many existing fetches waiting for a write lock in AsyncReadWriteLock in the Apollo V2 SDK. It reproduces most reliably when we have hundreds of fetch requests happening at once. Setting writeResultsToCache: false in RequestConfiguration reliably prevents the problem for us.
Multiple LLMs confirm this busy-waiting inside an actor will cause hangs:
while currentWriteTask != nil || !currentReadTasks.isEmpty {
await Task.yield()
}
This
await Task.yield()awaits, but does not exit the actor’s executor.It yields the task, not the actor lock.
So:
• The actor remains locked.
• No other task can enter to update currentReadTasks or currentWriteTask.
• Therefore the condition you’re waiting on can’t change.
• Therefore the loop never ends → deadlock.This is the single most common actor deadlock pattern.
When this occurs, our entire app becomes unusable until doing a force restart.
See full analysis here:
https://chatgpt.com/share/691f73fb-1684-8003-9ab8-500334ce038d
Version
2.0.3
Steps to reproduce the behavior
- Execute 100s of fetch requests at the same time
- Wait for fetches to complete
- Try loading more content using another fetch
In our case, 25-50% of the time the app will hang. Adding detailed logging into the Apollo caching code reveals that the fetches are all waiting to write to cache and never complete.
Logs
Anything else?
No response