Skip to content
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

[fixed] sub issue across leaf node connections - bad sub ref count #2124

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4568,6 +4568,7 @@ func (c *client) closeConnection(reason ClosedState) {
// Unregister
srv.removeClient(c)

notSpoke := !(kind == LEAF && c.isSpokeLeafNode())
// Update remote subscriptions.
if acc != nil && (kind == CLIENT || kind == LEAF) {
qsubs := map[string]*qsub{}
Expand All @@ -4576,7 +4577,9 @@ func (c *client) closeConnection(reason ClosedState) {
c.unsubscribe(acc, sub, true, false)
// Update route as normal for a normal subscriber.
if sub.queue == nil {
srv.updateRouteSubscriptionMap(acc, sub, -1)
if notSpoke {
srv.updateRouteSubscriptionMap(acc, sub, -1)
}
srv.updateLeafNodes(acc, sub, -1)
} else {
// We handle queue subscribers special in case we
Expand All @@ -4589,13 +4592,15 @@ func (c *client) closeConnection(reason ClosedState) {
qsubs[key] = &qsub{sub, 1}
}
}
if srv.gateway.enabled {
if srv.gateway.enabled && notSpoke {
srv.gatewayUpdateSubInterest(acc.Name, sub, -1)
}
}
// Process any qsubs here.
for _, esub := range qsubs {
srv.updateRouteSubscriptionMap(acc, esub.sub, -(esub.n))
if notSpoke {
srv.updateRouteSubscriptionMap(acc, esub.sub, -(esub.n))
}
srv.updateLeafNodes(acc, esub.sub, -(esub.n))
}
if prev := acc.removeClient(c); prev == 1 {
Expand Down
13 changes: 8 additions & 5 deletions server/leafnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,7 @@ func (c *client) processLeafUnsub(arg []byte) error {
}

updateGWs := false
spoke := c.isSpokeLeafNode()
// We store local subs by account and subject and optionally queue name.
// LS- will have the arg exactly as the key.
sub, ok := c.subs[string(arg)]
Expand All @@ -1661,11 +1662,13 @@ func (c *client) processLeafUnsub(arg []byte) error {
updateGWs = srv.gateway.enabled
}

// If we are routing subtract from the route map for the associated account.
srv.updateRouteSubscriptionMap(acc, sub, -1)
// Gateways
if updateGWs {
srv.gatewayUpdateSubInterest(acc.Name, sub, -1)
if !spoke {
// If we are routing subtract from the route map for the associated account.
srv.updateRouteSubscriptionMap(acc, sub, -1)
// Gateways
if updateGWs {
srv.gatewayUpdateSubInterest(acc.Name, sub, -1)
}
}
// Now check on leafnode updates for other leaf nodes.
srv.updateLeafNodes(acc, sub, -1)
Expand Down