bkad / prat

group chat with markdown served over websockets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

running process to evict orphaned client_ids in redis

bkad opened this issue · comments

To determine whether a user is online, we track all their open clients in a redis sets (under key: user-clients:email@address.com, adding and removing clients as they connect/disconnect.

It's possible, however, for a client to connect, and add their key to the open clients set, and then fail (due to a server shutting down, or some other error). In order to evict these orphaned client ids, one could run a separate process which sends hooks into the pub/sub system, sends pings to clients, who send back pongs which include their client ids. The process could then determine which keys are valid in the redis client pool and evict those which aren't.

Could be a nice chance to write some gevent code. Could have a master thread tracking all open clients, which spawns randomly offset X seconds from eachother and reaps a thread when the user the thread is tracking is has no open clients. Each child thread polls its open client pool every Y, sends pings, waits Z seconds, then evicts all client_ids which didnt send a pong.

has since been fixed