| 1599 | } |
| 1600 | |
| 1601 | bool 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; |
no test coverage detected