-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fix ARTChannel.setOptions
and ARTRealtimeChannel.setOptions
: Recreate ARTDataEncoder on ARTChannel options update
#1208
Conversation
`setOptions_nosync` is called from other classes that inherit `ARTChannel` class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for quickly working on this :)
Unfortunately, I find that the application crashes now when I call [channel setOptions:channelOptions];
. I've recorded this in a video that I attached. Notice that the application is paused at a breakpoint before calling [channel setOptions:channelOptions];
. After playing, it immediately crashes at a line of code related to this PR.
CleanShot.2021-11-04.at.23.49.11.2.mp4
fixed here 0a7fd0c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I tested these changes and there don't seem to be any crashes anymore. The crash turned out to be a race condition issue, as when I was testing it, it worked fine if using the debugger and stepping through the program more slowly. This led to @lukasz-szyszkowski trying multiple fixes, and we finally settled on dispatch_barrier_async
as it stopped causing the crashes.
I would appreciate others with more objective-C and especially those with objective-C + concurrency eyes here to approve if the race condition is fully fixed, not just a fix for some/most cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd like to better understand the motivation behind the synchronisation that you've added here. Could you please explain a little what you think was the cause of the crash that @ben-xD was seeing, and how this fixes it?
Perhaps I could also check that I've understood the meaning of the _nosync
method pattern that I've seen through the codebase. Is the idea of these methods that they should only be called on the SDK's internal queue, and hence shouldn't need any sort of synchronisation? If so, then shouldn't that mean that -setOptions_nosync:
here is already being called on _queue
and hence doesn't need to be dispatched there?
@ben-xD can you reproduce this crash one more time and type "po [address]" in the debug console, just curious what object hides under that address 0x*****8080. Triggering any synchronisation in all |
@maratal, after trying to reproduce the issue, the crashes no longer happened. I also reported this in slack: https://ably-real-time.slack.com/archives/CSQEKCE81/p1636137481110900?thread_ts=1636104128.094400&cid=CSQEKCE81 Therefore, the latest state of the PR looks good to merge, without any of the thread safety additions. |
ARTChannel.setOptions
and ARTRealtimeChannel.setOptions
: Recreate ARTDataEncoder on ARTChannel options update
No description provided.