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

Fix ARTChannel.setOptions and ARTRealtimeChannel.setOptions: Recreate ARTDataEncoder on ARTChannel options update #1208

Merged
merged 4 commits into from
Nov 8, 2021

Conversation

lukasz-szyszkowski
Copy link
Contributor

No description provided.

`setOptions_nosync` is called from other classes that inherit `ARTChannel` class
Copy link
Contributor

@ben-xD ben-xD left a 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

@ben-xD ben-xD self-requested a review November 4, 2021 21:19
@lukasz-szyszkowski
Copy link
Contributor Author

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

@lukasz-szyszkowski lukasz-szyszkowski requested review from maratal and removed request for lawrence-forooghian November 5, 2021 07:50
Copy link
Contributor

@ben-xD ben-xD left a 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.

Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian left a 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?

Source/ARTChannel.m Outdated Show resolved Hide resolved
Source/ARTChannel.m Show resolved Hide resolved
@maratal
Copy link
Collaborator

maratal commented Nov 5, 2021

@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 *_nosync: methods doesn't look good. Probably previous commit is more suitable for this fix, but we need to understand the nature of this crash better.

@ben-xD
Copy link
Contributor

ben-xD commented Nov 5, 2021

@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.

@ben-xD ben-xD changed the title Recreate ARTDataEncoder on ARTChannel options update Fix ARTChannel.setOptions and ARTRealtimeChannel.setOptions: Recreate ARTDataEncoder on ARTChannel options update Nov 8, 2021
@lukasz-szyszkowski
Copy link
Contributor Author

image

@lukasz-szyszkowski lukasz-szyszkowski merged commit 34d68ec into main Nov 8, 2021
@lukasz-szyszkowski lukasz-szyszkowski deleted the fix/recreate-data-encoder branch November 8, 2021 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Encrypt messages if a new ARTRealtimeChannelOptions or ARTChannelOptions containing cipher is set
5 participants