Skip to content

Commit 6de5d25

Browse files
authored
Merge pull request redis#5962 from oranagra/module_blocked_reply
slave corrupts replication stream when module blocked client uses large reply (or POSTPONED_ARRAY)
2 parents c24e320 + acba2fc commit 6de5d25

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/module.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,12 +3747,7 @@ void moduleHandleBlockedClients(void) {
37473747
* We need to glue such replies to the client output buffer and
37483748
* free the temporary client we just used for the replies. */
37493749
if (c) {
3750-
if (bc->reply_client->bufpos)
3751-
addReplyProto(c,bc->reply_client->buf,
3752-
bc->reply_client->bufpos);
3753-
if (listLength(bc->reply_client->reply))
3754-
listJoin(c->reply,bc->reply_client->reply);
3755-
c->reply_bytes += bc->reply_client->reply_bytes;
3750+
AddReplyFromClient(c, bc->reply_client);
37563751
}
37573752
freeClient(bc->reply_client);
37583753

src/networking.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,19 @@ void addReplySubcommandSyntaxError(client *c) {
744744
sdsfree(cmd);
745745
}
746746

747+
/* Append 'src' client output buffers into 'dst' client output buffers.
748+
* This function clears the output buffers of 'src' */
749+
void AddReplyFromClient(client *dst, client *src) {
750+
if (prepareClientToWrite(dst) != C_OK)
751+
return;
752+
addReplyProto(dst,src->buf, src->bufpos);
753+
if (listLength(src->reply))
754+
listJoin(dst->reply,src->reply);
755+
dst->reply_bytes += src->reply_bytes;
756+
src->reply_bytes = 0;
757+
src->bufpos = 0;
758+
}
759+
747760
/* Copy 'src' client output buffers into 'dst' client output buffers.
748761
* The function takes care of freeing the old output buffers of the
749762
* destination client. */

src/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,7 @@ void addReplyNullArray(client *c);
15291529
void addReplyBool(client *c, int b);
15301530
void addReplyVerbatim(client *c, const char *s, size_t len, const char *ext);
15311531
void addReplyProto(client *c, const char *s, size_t len);
1532+
void AddReplyFromClient(client *c, client *src);
15321533
void addReplyBulk(client *c, robj *obj);
15331534
void addReplyBulkCString(client *c, const char *s);
15341535
void addReplyBulkCBuffer(client *c, const void *p, size_t len);

0 commit comments

Comments
 (0)