[FIXED] Data RACE on Unsubscribe when client connection is closed

Resolves #331
This commit is contained in:
Ivan Kozlovic
2016-08-17 16:46:34 -06:00
parent 14f5d0919c
commit 811e0868ed
2 changed files with 5 additions and 1 deletions

View File

@@ -882,10 +882,12 @@ func (c *client) deliverMsg(sub *subscription, mh, msg []byte) {
// unsubscribe and drop message on the floor.
if sub.nm == sub.max {
c.Debugf("Auto-unsubscribe limit of %d reached for sid '%s'\n", sub.max, string(sub.sid))
defer client.unsubscribe(sub)
// Due to defer, reverse the code order so that execution
// is consistent with other cases where we unsubscribe.
if shouldForward {
defer client.srv.broadcastUnSubscribe(sub)
}
defer client.unsubscribe(sub)
} else if sub.nm > sub.max {
c.Debugf("Auto-unsubscribe limit [%d] exceeded\n", sub.max)
client.mu.Unlock()

View File

@@ -575,10 +575,12 @@ func (s *Server) broadcastUnSubscribe(sub *subscription) {
}
rsid := routeSid(sub)
maxStr := _EMPTY_
sub.client.mu.Lock()
// Set max if we have it set and have not tripped auto-unsubscribe
if sub.max > 0 && sub.nm < sub.max {
maxStr = fmt.Sprintf(" %d", sub.max)
}
sub.client.mu.Unlock()
proto := fmt.Sprintf(unsubProto, rsid, maxStr)
s.broadcastInterestToRoutes(proto)
}