Conversation
In some circumstances we do two contradicting calls in almost the same time. One of them is a call to heartbeat endpoint and the other is to leave endpoint. The reason why those call could happen in almost the same time is because heartbeat calls are done periodically on separate thread and leave calls are happening due to user actions. This means that sooner or later this situation will happen and pubnub presence system will generate join event and leave event (usually in this order), but then another timeout event when presence timeout expires. To prevent it from happening I've decided to limit the number of concurrent calls to only those two endpoints to just one. This is done on the okhttp client level. Because those two calls can be ordered only two ways we can provide an analysis of why this change might work. Let's first concentrate on situation when heartbeat call is already happening and unsubscribe method is being called: * leave call will go to the internal queue of calls of okhttp client due to limit of concurrent calls * unsubscribe method internally will try to cancel the heartbeat call and schedule timer with another heartbeat call (but with different set of channels) * heartbeat finishes (either normally, or by being cancelled), this usually do not generate any events, but it might generate join event * http leave call can finally proceed, which generates leave event * because the calls have been done sequentially there's no timeout event In case when leave call is already ongoing and the schedule heartbeat timer is trying to make heartbeat request: * heartbeat request goes to client's internal queue to wait on leave to be finished * in the meantime usubscribe method internally cancels the timer and cancels the heartbeat request before it has time to start * leave request ends, and leave event is being generated * there's no timeout event, and the presence didn't have chance to be extended
Chesteer89
reviewed
Apr 28, 2022
| this.signatureInterceptor = new SignatureInterceptor(pubNubInstance); | ||
|
|
||
| if (!pubNubInstance.getConfiguration().isGoogleAppEngineNetworking()) { | ||
|
|
kleewho
commented
Apr 28, 2022
| <Class name="com.pubnub.api.PubNubException"/> | ||
| <Field name="affectedCall"/> | ||
| <Bug pattern="URF_UNREAD_FIELD"/> | ||
| </Match> |
Contributor
Author
There was a problem hiding this comment.
Don't know why it started to be a problem now. I didn't touch it at all yet here it is
marcin-cebo
approved these changes
Apr 29, 2022
Contributor
Author
|
@client-engineering-bot release as v6.0.1 |
|
🚀 Release successfully completed 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: Do heartbeat and leave calls sequentially
It prevents race condition between these two calls and "phantom" join after leave