Skip to content

Commit

Permalink
Fix potential race in pubsub
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnSully committed Oct 25, 2019
1 parent 3013799 commit a91f58b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/pubsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,11 @@ int pubsubPublishMessage(robj *channel, robj *message) {
client *c = reinterpret_cast<client*>(ln->value);
if (c->flags & CLIENT_CLOSE_ASAP) // avoid blocking if the write will be ignored
continue;
fastlock_lock(&c->lock);
if (FCorrectThread(c))
fastlock_lock(&c->lock);
addReplyPubsubMessage(c,channel,message);
fastlock_unlock(&c->lock);
if (FCorrectThread(c))
fastlock_unlock(&c->lock);
receivers++;
}
}
Expand All @@ -321,10 +323,12 @@ int pubsubPublishMessage(robj *channel, robj *message) {
{
if (pat->pclient->flags & CLIENT_CLOSE_ASAP)
continue;
fastlock_lock(&pat->pclient->lock);
if (FCorrectThread(pat->pclient))
fastlock_lock(&pat->pclient->lock);
addReplyPubsubPatMessage(pat->pclient,
pat->pattern,channel,message);
fastlock_unlock(&pat->pclient->lock);
if (FCorrectThread(pat->pclient))
fastlock_unlock(&pat->pclient->lock);
receivers++;
}
}
Expand Down

0 comments on commit a91f58b

Please sign in to comment.