Unverified Commit e7047ec2 authored by Yossi Gottlieb's avatar Yossi Gottlieb Committed by GitHub
Browse files

Fix crashes with io-threads-do-reads enabled. (#8230)

Normally IO threads should simply read data from the socket into the
buffer and attempt to parse it.

If a protocol error is detected, a reply is generated which may result
with installing a write handler which is not thread safe. This fix
delays that until the client is processed back in the main thread.

Fixes #8220
parent 411c18bb
...@@ -259,8 +259,14 @@ int prepareClientToWrite(client *c) { ...@@ -259,8 +259,14 @@ int prepareClientToWrite(client *c) {
if (!c->conn) return C_ERR; /* Fake client for AOF loading. */ if (!c->conn) return C_ERR; /* Fake client for AOF loading. */
/* Schedule the client to write the output buffers to the socket, unless /* Schedule the client to write the output buffers to the socket, unless
* it should already be setup to do so (it has already pending data). */ * it should already be setup to do so (it has already pending data).
if (!clientHasPendingReplies(c)) clientInstallWriteHandler(c); *
* If CLIENT_PENDING_READ is set, we're in an IO thread and should
* not install a write handler. Instead, it will be done by
* handleClientsWithPendingReadsUsingThreads() upon return.
*/
if (!clientHasPendingReplies(c) && !(c->flags & CLIENT_PENDING_READ))
clientInstallWriteHandler(c);
/* Authorize the caller to queue in the output buffer of this client. */ /* Authorize the caller to queue in the output buffer of this client. */
return C_OK; return C_OK;
...@@ -3509,6 +3515,12 @@ int handleClientsWithPendingReadsUsingThreads(void) { ...@@ -3509,6 +3515,12 @@ int handleClientsWithPendingReadsUsingThreads(void) {
} }
} }
processInputBuffer(c); processInputBuffer(c);
/* We may have pending replies if a thread readQueryFromClient() produced
* replies and did not install a write handler (it can't).
*/
if (!(c->flags & CLIENT_PENDING_WRITE) && clientHasPendingReplies(c))
clientInstallWriteHandler(c);
} }
/* Update processed count on server */ /* Update processed count on server */
......
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