Skip to content

Commit c575e7d

Browse files
committed
Avoid crash due to excessive posted functions for AOF rewrite
1 parent e603e57 commit c575e7d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/aof.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,14 @@ void aofRewriteBufferAppend(unsigned char *s, unsigned long len) {
165165

166166
/* Install a file event to send data to the rewrite child if there is
167167
* not one already. */
168-
aePostFunction(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, []{
169-
if (g_pserver->aof_pipe_write_data_to_child >= 0)
170-
aeCreateFileEvent(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, g_pserver->aof_pipe_write_data_to_child, AE_WRITABLE, aofChildWriteDiffData, NULL);
171-
});
168+
if (!g_pserver->aof_rewrite_pending) {
169+
g_pserver->aof_rewrite_pending = true;
170+
aePostFunction(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, [] {
171+
g_pserver->aof_rewrite_pending = false;
172+
if (g_pserver->aof_pipe_write_data_to_child >= 0)
173+
aeCreateFileEvent(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, g_pserver->aof_pipe_write_data_to_child, AE_WRITABLE, aofChildWriteDiffData, NULL);
174+
});
175+
}
172176
}
173177

174178
/* Write the buffer (possibly composed of multiple blocks) into the specified

src/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,7 @@ struct redisServer {
17331733
int aof_stop_sending_diff; /* If true stop sending accumulated diffs
17341734
to child process. */
17351735
sds aof_child_diff; /* AOF diff accumulator child side. */
1736+
int aof_rewrite_pending = 0; /* is a call to aofChildWriteDiffData already queued? */
17361737
/* RDB persistence */
17371738
long long dirty; /* Changes to DB from the last save */
17381739
long long dirty_before_bgsave; /* Used to restore dirty on failed BGSAVE */

0 commit comments

Comments
 (0)