MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / freeClient

Function freeClient

src/networking.cpp:1601–1751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1599}
1600
1601bool freeClient(client *c) {
1602 listNode *ln;
1603 serverAssert(c->conn == nullptr || GlobalLocksAcquired());
1604 AssertCorrectThread(c);
1605 std::unique_lock<decltype(c->lock)> ulock(c->lock);
1606
1607 /* If a client is protected, yet we need to free it right now, make sure
1608 * to at least use asynchronous freeing. */
1609 if (c->flags & CLIENT_PROTECTED || c->casyncOpsPending || c->replstate == SLAVE_STATE_FASTSYNC_TX) {
1610 freeClientAsync(c);
1611 return false;
1612 }
1613
1614 /* For connected clients, call the disconnection event of modules hooks. */
1615 if (c->conn) {
1616 moduleFireServerEvent(REDISMODULE_EVENT_CLIENT_CHANGE,
1617 REDISMODULE_SUBEVENT_CLIENT_CHANGE_DISCONNECTED,
1618 c);
1619 }
1620
1621 /* Notify module system that this client auth status changed. */
1622 moduleNotifyUserChanged(c);
1623
1624 /* If this client was scheduled for async freeing we need to remove it
1625 * from the queue. Note that we need to do this here, because later
1626 * we may call replicationCacheMaster() and the client should already
1627 * be removed from the list of clients to free. */
1628 if (c->flags & CLIENT_CLOSE_ASAP) {
1629 std::unique_lock<fastlock> ul(g_lockasyncfree);
1630 ln = listSearchKey(g_pserver->clients_to_close,c);
1631 serverAssert(ln != NULL);
1632 listDelNode(g_pserver->clients_to_close,ln);
1633 }
1634
1635 /* If it is our master that's being disconnected we should make sure
1636 * to cache the state to try a partial resynchronization later.
1637 *
1638 * Note that before doing this we make sure that the client is not in
1639 * some unexpected state, by checking its flags. */
1640 if (FActiveMaster(c)) {
1641 serverLog(LL_WARNING,"Connection with master lost.");
1642 if (!(c->flags & (CLIENT_PROTOCOL_ERROR|CLIENT_BLOCKED))) {
1643 c->flags &= ~(CLIENT_CLOSE_ASAP|CLIENT_CLOSE_AFTER_REPLY);
1644 replicationCacheMaster(MasterInfoFromClient(c), c);
1645 return false;
1646 }
1647 }
1648
1649 /* Log link disconnection with replica */
1650 if (getClientType(c) == CLIENT_TYPE_SLAVE) {
1651 serverLog(LL_WARNING,"Connection with replica %s lost.",
1652 replicationGetSlaveName(c));
1653 }
1654
1655 /* Free the query buffer */
1656 sdsfree(c->querybuf);
1657 sdsfree(c->pending_querybuf);
1658 c->querybuf = NULL;

Callers 15

putSlaveOnlineFunction · 0.70
sendBulkToSlaveFunction · 0.70
disconnectMasterFunction · 0.70
~RemoteMasterStateMethod · 0.70
replicaReplayCommandFunction · 0.70
clientsCronHandleTimeoutFunction · 0.70
closeClientOnOverloadFunction · 0.70
moduleFreeContextFunction · 0.70
RM_CallFunction · 0.70

Calls 15

GlobalLocksAcquiredFunction · 0.85
freeClientAsyncFunction · 0.85
moduleFireServerEventFunction · 0.85
moduleNotifyUserChangedFunction · 0.85
listSearchKeyFunction · 0.85
listDelNodeFunction · 0.85
FActiveMasterFunction · 0.85
serverLogFunction · 0.85
replicationCacheMasterFunction · 0.85
MasterInfoFromClientFunction · 0.85
getClientTypeFunction · 0.85
replicationGetSlaveNameFunction · 0.85

Tested by

no test coverage detected