Skip to content

Commit

Permalink
Merge pull request #12 from sendbird/fix/fileno
Browse files Browse the repository at this point in the history
Fix error while unregistering if connection is closed
  • Loading branch information
dlunch authored Jul 24, 2023
2 parents 0797040 + 9a55a02 commit 23f3a10
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions kombu/transport/redis_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def __init__(self, key):
self.timeout = None

class ClusterPoller(MultiChannelPoller):
def __init__(self):
super().__init__()
self._sock_to_fd = {}

def _register(self, channel, client, conn, cmd):
ident = (channel, client, conn, cmd)
Expand Down Expand Up @@ -179,17 +182,20 @@ def _register(self, channel, client, conn, cmd):
sock = conn.client.connection._sock
self._fd_to_chan[sock.fileno()] = (channel, conn, cmd)
self._chan_to_sock[ident] = sock
self._sock_to_fd[sock] = sock.fileno()
self.poller.register(sock, self.eventflags)

def _unregister(self, channel, client, conn, cmd):
sock = self._chan_to_sock[(channel, client, conn, cmd)]
fd = self._sock_to_fd[sock]

if conn.client:
conn.client.close()
conn.client = None

sock = self._chan_to_sock[(channel, client, conn, cmd)]

del self._fd_to_chan[sock.fileno()]
del self._fd_to_chan[fd]
del self._chan_to_sock[(channel, client, conn, cmd)]
del self._sock_to_fd[sock]

self.poller.unregister(sock)

Expand Down

0 comments on commit 23f3a10

Please sign in to comment.