| 1303 | } |
| 1304 | |
| 1305 | void freeClient(client *c) { |
| 1306 | listNode *ln; |
| 1307 | |
| 1308 | /* If a client is protected, yet we need to free it right now, make sure |
| 1309 | * to at least use asynchronous freeing. */ |
| 1310 | if (c->flags & CLIENT_PROTECTED) { |
| 1311 | freeClientAsync(c); |
| 1312 | return; |
| 1313 | } |
| 1314 | |
| 1315 | /* For connected clients, call the disconnection event of modules hooks. */ |
| 1316 | if (c->conn) { |
| 1317 | moduleFireServerEvent(REDISMODULE_EVENT_CLIENT_CHANGE, |
| 1318 | REDISMODULE_SUBEVENT_CLIENT_CHANGE_DISCONNECTED, |
| 1319 | c); |
| 1320 | } |
| 1321 | |
| 1322 | /* Notify module system that this client auth status changed. */ |
| 1323 | moduleNotifyUserChanged(c); |
| 1324 | |
| 1325 | /* If this client was scheduled for async freeing we need to remove it |
| 1326 | * from the queue. Note that we need to do this here, because later |
| 1327 | * we may call replicationCacheMaster() and the client should already |
| 1328 | * be removed from the list of clients to free. */ |
| 1329 | if (c->flags & CLIENT_CLOSE_ASAP) { |
| 1330 | ln = listSearchKey(server.clients_to_close,c); |
| 1331 | serverAssert(ln != NULL); |
| 1332 | listDelNode(server.clients_to_close,ln); |
| 1333 | } |
| 1334 | |
| 1335 | /* If it is our master that's being disconnected we should make sure |
| 1336 | * to cache the state to try a partial resynchronization later. |
| 1337 | * |
| 1338 | * Note that before doing this we make sure that the client is not in |
| 1339 | * some unexpected state, by checking its flags. */ |
| 1340 | if (server.master && c->flags & CLIENT_MASTER) { |
| 1341 | serverLog(LL_WARNING,"Connection with master lost."); |
| 1342 | if (!(c->flags & (CLIENT_PROTOCOL_ERROR|CLIENT_BLOCKED))) { |
| 1343 | c->flags &= ~(CLIENT_CLOSE_ASAP|CLIENT_CLOSE_AFTER_REPLY); |
| 1344 | replicationCacheMaster(c); |
| 1345 | return; |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | /* Log link disconnection with slave */ |
| 1350 | if (getClientType(c) == CLIENT_TYPE_SLAVE) { |
| 1351 | serverLog(LL_WARNING,"Connection with replica %s lost.", |
| 1352 | replicationGetSlaveName(c)); |
| 1353 | } |
| 1354 | |
| 1355 | /* Free the query buffer */ |
| 1356 | sdsfree(c->querybuf); |
| 1357 | sdsfree(c->pending_querybuf); |
| 1358 | c->querybuf = NULL; |
| 1359 | |
| 1360 | /* Deallocate structures used to block on blocking ops. */ |
| 1361 | if (c->flags & CLIENT_BLOCKED) unblockClient(c); |
| 1362 | dictRelease(c->bpop.keys); |
no test coverage detected