-
Notifications
You must be signed in to change notification settings - Fork 6
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: synchronize cloud data client operations properly #204
Conversation
src/main/java/com/aws/greengrass/shadowmanager/ShadowManager.java
Outdated
Show resolved
Hide resolved
src/main/java/com/aws/greengrass/shadowmanager/ShadowManager.java
Outdated
Show resolved
Hide resolved
Can we accomplish this without adding more threads? In startSyncingShadows, we can check if connected in a non-blocking way |
Unit Tests Coverage Report
Minimum allowed coverage is Generated by 🐒 cobertura-action against e5f94b4 |
Integration Tests Coverage Report
Minimum allowed coverage is Generated by 🐒 cobertura-action against e5f94b4 |
src/main/java/com/aws/greengrass/shadowmanager/sync/CloudDataClient.java
Show resolved
Hide resolved
36e0338
to
0c3db80
Compare
src/main/java/com/aws/greengrass/shadowmanager/sync/CloudDataClient.java
Show resolved
Hide resolved
7f67acf
to
da7df14
Compare
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.
lgtm, just some small cleanup suggestions
src/main/java/com/aws/greengrass/shadowmanager/sync/CloudDataClient.java
Outdated
Show resolved
Hide resolved
src/main/java/com/aws/greengrass/shadowmanager/sync/CloudDataClient.java
Show resolved
Hide resolved
5e60507
to
45b3a6d
Compare
src/main/java/com/aws/greengrass/shadowmanager/sync/CloudDataClient.java
Show resolved
Hide resolved
@@ -290,6 +290,7 @@ void GIVEN_100_synced_shadows_WHEN_unsubscribeForAllShadowsTopics_THEN_unsubscri | |||
} | |||
|
|||
cloudDataClient.unsubscribeForAllShadowsTopics(); | |||
TimeUnit.MILLISECONDS.sleep(5000); |
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.
what's this for?
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.
cloudDataClient.unsubscribeForAllShadowsTopics();
now runs in a separate thread with the current changes.
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.
yeah ideally we have a way of waiting via a latch or something
Issue #, if available:
Description of changes:
Run mqtt callbacks in a separate thread to avoid a deadlock situation that happens when the Shadow manager component enters into RUNNING state before the MQTT client connection is successfully created acc to GG.
Mqtt connect future will be completed with the client only after the first on connect callbacks are triggered. Shadow manager onConnect callback needs the client to be fully formed (connect future to be completed with the mqtt client) for it to use subscribe with it. Hence, the subscriptions triggered from the callback timeout waiting for the client.
During SM start up, startSyncingShadows is called which calls updateSubscriptions on the cloudDataClient. That spins up a new thread from the executor service pool which run this private synchronized updateSubscriptions on the cloudDataClient. This runs indefinitely as mqtt subscribe op was never successful.
Now, mqtt callback thread is blocked at updateSubscriptions in startSyncShadows because that method is also synchronized on the cloudDataClient instance and we can't have two synchronized methods interleaving on the same instance.
Why is this change necessary:
More info:
When the MQTT client is created for the first time, onConnect (one-time) callbacks are run before the connectFuture is completed with the client. Only when these callbacks are completed, the
connectFuture
is completed.But, in the case where Shadow manager component enters into RUNNING state before the MQTT client connection is successfully created for the first time, onConnectionResumed callback is triggered when the mqtt client is created for the first time. This callback uses subscribes to topics using mqtt client. However, in order to subscribe using the mqtt client, the
connectFuture
should be fully completed resulting in a deadlock situation.The fix is to run the callback in a separate thread, so the
connectFuture
is completed without being blocked.How was this change tested:
Any additional information or context required to review the change:
Checklist:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.