-
Notifications
You must be signed in to change notification settings - Fork 115
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
full node streaming - reusing subscription ids #2518
Conversation
WalkthroughThe pull request introduces significant changes to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- protocol/streaming/full_node_streaming_manager.go (8 hunks)
🧰 Additional context used
🔇 Additional comments (6)
protocol/streaming/full_node_streaming_manager.go (6)
38-38
: Approved: AddedactiveSubscriptionIds
to manage active subscriptionsThe addition of
activeSubscriptionIds
map is appropriate for tracking the active subscription IDs efficiently.
109-109
: Approved: InitializedactiveSubscriptionIds
mapInitializing
activeSubscriptionIds
usingmake(map[uint32]bool)
correctly sets up the map for use.
205-205
: Approved: AssigningsubscriptionId
to new subscriptionAssigning the generated
subscriptionId
to theOrderbookSubscription
ensures each subscription is identified correctly.
244-244
: Approved: MarkingsubscriptionId
as activeAdding the
subscriptionId
toactiveSubscriptionIds
upon subscription creation is appropriate for tracking active IDs.
296-296
: Approved: RemovingsubscriptionId
fromactiveSubscriptionIds
Deleting the
subscriptionId
fromactiveSubscriptionIds
when a subscription is removed allows for ID reuse and prevents leaks.
202-202
: Verify the uniqueness ofsubscriptionId
generatedEnsure that the
subscriptionId
obtained fromgetNextAvailableSubscriptionId()
is unique and does not collide with existing subscriptions.Run the following script to check for proper handling of
subscriptionId
allocations and deallocations:
func (sm *FullNodeStreamingManagerImpl) getNextAvailableSubscriptionId() uint32 { | ||
id := uint32(0) | ||
for _, inUse := sm.activeSubscriptionIds[id]; inUse; _, inUse = sm.activeSubscriptionIds[id] { | ||
id = id + uint32(1) | ||
} | ||
return id | ||
} |
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.
Fix the incorrect for loop in getNextAvailableSubscriptionId
The getNextAvailableSubscriptionId
function contains a for loop with incorrect syntax and logic, which may lead to runtime errors or unintended behavior.
The current for loop:
func (sm *FullNodeStreamingManagerImpl) getNextAvailableSubscriptionId() uint32 {
id := uint32(0)
for _, inUse := sm.activeSubscriptionIds[id]; inUse; _, inUse = sm.activeSubscriptionIds[id] {
id = id + uint32(1)
}
return id
}
Issues with the loop:
- The for loop syntax is unconventional and may not compile or behave as expected.
- The assignment and condition checks within the loop are not correctly structured.
Proposed Fix:
Refactor the for loop to correctly iterate until an unused subscriptionId
is found.
Apply this diff to fix the loop:
func (sm *FullNodeStreamingManagerImpl) getNextAvailableSubscriptionId() uint32 {
id := uint32(0)
- for _, inUse := sm.activeSubscriptionIds[id]; inUse; _, inUse = sm.activeSubscriptionIds[id] {
- id = id + uint32(1)
+ for {
+ if _, inUse := sm.activeSubscriptionIds[id]; !inUse {
+ break
+ }
+ id++
}
return id
}
Reuse subscription ids. Especially after we tag the metrics with subscription ids, keeps the metrics cardinalities low
Summary by CodeRabbit
New Features
Bug Fixes
Refactor