Skip to content

Commit

Permalink
Don't write replies if close the client ASAP
Browse files Browse the repository at this point in the history
  • Loading branch information
ShooterIT committed Aug 24, 2020
1 parent 70a80ef commit e8fc322
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/networking.c
Expand Up @@ -222,6 +222,9 @@ int prepareClientToWrite(client *c) {
* handler since there is no socket at all. */
if (c->flags & (CLIENT_LUA|CLIENT_MODULE)) return C_OK;

/* If CLIENT_CLOSE_ASAP flag is set, we need not write anything. */
if (c->flags & CLIENT_CLOSE_ASAP) return C_ERR;

/* CLIENT REPLY OFF / SKIP handling: don't send replies. */
if (c->flags & (CLIENT_REPLY_OFF|CLIENT_REPLY_SKIP)) return C_ERR;

Expand Down Expand Up @@ -1377,6 +1380,9 @@ int handleClientsWithPendingWrites(void) {
* that may trigger write error or recreate handler. */
if (c->flags & CLIENT_PROTECTED) continue;

/* Don't write to clients that are going to be closed anyway. */
if (c->flags & CLIENT_CLOSE_ASAP) continue;

/* Try to write buffers to the client socket. */
if (writeToClient(c,0) == C_ERR) continue;

Expand Down Expand Up @@ -3015,6 +3021,14 @@ int handleClientsWithPendingWritesUsingThreads(void) {
while((ln = listNext(&li))) {
client *c = listNodeValue(ln);
c->flags &= ~CLIENT_PENDING_WRITE;

/* Remove clients from the list of pending writes since
* they are going to be closed ASAP. */
if (c->flags & CLIENT_CLOSE_ASAP) {
listDelNode(server.clients_pending_write, ln);
continue;
}

int target_id = item_id % server.io_threads_num;
listAddNodeTail(io_threads_list[target_id],c);
item_id++;
Expand Down

0 comments on commit e8fc322

Please sign in to comment.