Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in WebSocketTransport due to data races #3512

Closed
tahirmt opened this issue Feb 4, 2025 · 1 comment · Fixed by apollographql/apollo-ios-dev#599
Closed

Crash in WebSocketTransport due to data races #3512

tahirmt opened this issue Feb 4, 2025 · 1 comment · Fixed by apollographql/apollo-ios-dev#599
Labels
bug Generally incorrect behavior needs investigation

Comments

@tahirmt
Copy link
Contributor

tahirmt commented Feb 4, 2025

Summary

In WebSocketTransport the subscribers dictionary is not Atomic and is modified using the processingQueue however it is read in processMessage(text:) function which is called on a different thread by the WebSocketClient. This can lead to a data race if the updates are coming in on the web socket very fast and at the same time new subscriptions are started or stopped.

By adding @Atomic to the subscribers variable, this crash is completely resolved.

While I didn't encounter a crash on subscriptions variable, I suspect the same can happen there.

Version

1.16.1

Steps to reproduce the behavior

This is tough because for us it only happened during a really high load scenario where we were receiving tens of messages per second on the web socket and a lot of those messages also resulted in our code stopping and starting subscriptions.

We have seen this crash happen on production as well. The crash shows up as EXC_BAD_ACCESS KERN_INVALID_ADDRESS

Logs

Anything else?

No response

Copy link
Contributor

github-actions bot commented Feb 4, 2025

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior needs investigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant