Repository navigation
Add ability to unsubscribe - #44
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #44 +/- ##
==========================================
+ Coverage 94.50% 94.68% +0.17%
==========================================
Files 6 6
Lines 273 282 +9
==========================================
+ Hits 258 267 +9
Misses 15 15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
callumforrester
force-pushed
the
subscribe-race-condition
branch
from
October 13, 2025 14:51
81d4b74 to
b120e14
Compare
callumforrester
force-pushed
the
subscribe-race-condition
branch
from
October 13, 2025 15:03
b120e14 to
5334140
Compare
callumforrester
added a commit
to DiamondLightSource/blueapi
that referenced
this pull request
Oct 13, 2025
Pending DiamondLightSource/bluesky-stomp#44 Unsubsribe from STOMP messages after use to prevent a race condition. The client already disconnects from the stomp broker after its context exits, but any subscriptions are resubscribed when the client reconnects, they need to be explicitly unsubscribed.
callumforrester
added a commit
to DiamondLightSource/blueapi
that referenced
this pull request
Oct 13, 2025
Pending DiamondLightSource/bluesky-stomp#44 Unsubsribe from STOMP messages after use to prevent a race condition. The client already disconnects from the stomp broker after its context exits, but any subscriptions are resubscribed when the client reconnects, they need to be explicitly unsubscribed.
callumforrester
force-pushed
the
subscribe-race-condition
branch
from
October 14, 2025 10:03
5334140 to
615f9df
Compare
ZohebShaikh
reviewed
Oct 14, 2025
Comment on lines
+342
to
+344
| del self._subscriptions[ | ||
| sub_id | ||
| ] # Ensure that client won't re-subscribe upon re-connection |
Contributor
There was a problem hiding this comment.
Suggested change
| del self._subscriptions[ | |
| sub_id | |
| ] # Ensure that client won't re-subscribe upon re-connection | |
| del self._subscriptions[ | |
| sub_id | |
| ] # Ensure that client won't re-subscribe upon re-connection |
?
Contributor
Author
There was a problem hiding this comment.
If you subscribe without connecting it caches the subscription for after connection.
# Caches callback for when connected to the broker
client.subscribe(my_queue, callback_1)
# Actually does the I/O with broker to subscribe for callback_1
client.connect()
# Immediately does I/O with broker to subscribe for callback_2
client.subscribe(my_queue, callback_2) So we want unsubscribe to mirror that behaviour
# Caches both callbacks for later
s1 = client.subscribe(my_queue, callback_1)
s2 = client.subscribe(my_queue, callback_2)
# Removes first cached callback
client.unsubscribe(s1)
# Does I/O for second subscription
client.connect()
# Does I/O for unsubscribing for second callback
client.unsubscribe(s2)If we do as you suggest that then both s1 and s2 will be cached but the first unsubscribe call will be a no-op so connect() will still do both subscriptions, which is confusing.
ZohebShaikh
approved these changes
Oct 14, 2025
callumforrester
added a commit
to DiamondLightSource/blueapi
that referenced
this pull request
Oct 15, 2025
Pending DiamondLightSource/bluesky-stomp#44 Unsubsribe from STOMP messages after use to prevent a race condition. The client already disconnects from the stomp broker after its context exits, but any subscriptions are resubscribed when the client reconnects, they need to be explicitly unsubscribed.
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.
Add ability to unsubscribe from queues and topics so clients can clean up old subscriptions to avoid race conditions.
This preserves the extant and implicit behaviour of resubscribing on reconnection. We could discuss whether we actually want bluesky-stomp to do this, although I suggest that's for later (and a major version change).
CI broken pending #43