Skip to content

Resolve race condition by ensuring that op=connected has been received before sending a new subscribe event #48

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

Merged
merged 2 commits into from
May 3, 2017

Conversation

jhansche
Copy link
Contributor

ParseLiveQueryClient.subscribe() checks if the socket state is "CONNECTED" before sending the subscribe event. If it's not, it triggers a reconnect.

The problem is that when the socket connects, we also send the op=connect event to the server, and wait for the server to respond with op=connected. At the time of op=connected, we then send any pending subscribe messages.

If a subscribe request comes in after the socket is connected, but before the op=connected message comes from the server, we will end up with that subscription duplicated, and we'll receive duplicated events as a result.

@jhansche jhansche requested review from rogerhu and mmimeault April 27, 2017 19:13
@codecov
Copy link

codecov bot commented Apr 27, 2017

Codecov Report

Merging #48 into master will increase coverage by 0.98%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #48      +/-   ##
============================================
+ Coverage     67.13%   68.11%   +0.98%     
- Complexity       78       82       +4     
============================================
  Files            11       11              
  Lines           359      367       +8     
  Branches         24       24              
============================================
+ Hits            241      250       +9     
+ Misses          104      103       -1     
  Partials         14       14
Impacted Files Coverage Δ Complexity Δ
.../main/java/com/parse/ParseLiveQueryClientImpl.java 75.58% <100%> (+1.44%) 56 <3> (+4) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26043f9...1355e79. Read the comment docs.

@@ -88,7 +89,8 @@ private static URI getDefaultUri() {
Subscription<T> subscription = new Subscription<>(requestId, query);
subscriptions.append(requestId, subscription);

if (inAnyState(WebSocketClient.State.CONNECTED)) {
// TODO: differentiate between state=CONNECTED, vs received op=connected response
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, this should have been removed

@jhansche
Copy link
Contributor Author

jhansche commented May 3, 2017

@rogerhu @mmimeault ping? We'd like to get this merged to at least get a SNAPSHOT built in order to fix the bug in our app.

@rogerhu
Copy link
Contributor

rogerhu commented May 3, 2017

Nice find and thanks for the test.

@rogerhu rogerhu merged commit 5935026 into parse-community:master May 3, 2017
@meustice
Copy link

meustice commented May 4, 2017

Can we please get a new release or snapshot built to include these changes? We're working towards a push of a release on our Android platform very soon.

@rogerhu
Copy link
Contributor

rogerhu commented May 4, 2017

We have auto snapshots via Sonatype here: https://oss.sonatype.org/content/repositories/snapshots/com/parse/parse-livequery-android/1.0.3-SNAPSHOT/

I can push a release though.

@meustice
Copy link

meustice commented May 4, 2017

release works if thats easy enough. thanks.

@meustice
Copy link

meustice commented May 5, 2017

@rogerhu was the release published? we're not seeing it available on sonatype yet.

@rogerhu
Copy link
Contributor

rogerhu commented May 5, 2017

It's on jCenter (point your Gradle config to jcenter() instead of mavenCentral()) already.

Getting Bintray to approve auto-syncing to Sonatype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants