Commit 76b7233a authored by antirez's avatar antirez
Browse files

fixed a deadlock caused by too much finished processes in queue so that I/O...

fixed a deadlock caused by too much finished processes in queue so that I/O clients writing to the wirte side of the pipe used to awake the main thread where blocking. Then a BGSAVE started waiting for the last active thread to finish, condition impossible because all the I/O threads where blocking on threads. Takes this as a note to myself...
parent 621d5c19
...@@ -7768,6 +7768,8 @@ static void spawnIOThread(void) { ...@@ -7768,6 +7768,8 @@ static void spawnIOThread(void) {
* fork() in order to BGSAVE or BGREWRITEAOF. */ * fork() in order to BGSAVE or BGREWRITEAOF. */
static void waitEmptyIOJobsQueue(void) { static void waitEmptyIOJobsQueue(void) {
while(1) { while(1) {
int io_processed_len;
lockThreadedIO(); lockThreadedIO();
if (listLength(server.io_newjobs) == 0 && if (listLength(server.io_newjobs) == 0 &&
listLength(server.io_processing) == 0 && listLength(server.io_processing) == 0 &&
...@@ -7776,9 +7778,19 @@ static void waitEmptyIOJobsQueue(void) { ...@@ -7776,9 +7778,19 @@ static void waitEmptyIOJobsQueue(void) {
unlockThreadedIO(); unlockThreadedIO();
return; return;
} }
/* While waiting for empty jobs queue condition we post-process some
* finshed job, as I/O threads may be hanging trying to write against
* the io_ready_pipe_write FD but there are so much pending jobs that
* it's blocking. */
io_processed_len = listLength(server.io_processed);
unlockThreadedIO(); unlockThreadedIO();
if (io_processed_len) {
vmThreadedIOCompletedJob(NULL,server.io_ready_pipe_read,NULL,0);
usleep(1000); /* 1 millisecond */
} else {
usleep(10000); /* 10 milliseconds */ usleep(10000); /* 10 milliseconds */
} }
}
} }
static void vmReopenSwapFile(void) { static void vmReopenSwapFile(void) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment