Skip to content

Commit 24788e3

Browse files
committed
libev reactor: Return from watchers for closed connection
Previous commit defered socket close until watchers are stopped, but there is one more case worth considering. If during one libev loop iteration socket gets ready for both read and write, then both watchers will be called. If one decides to close the connection, the other one will still get called anyway. This shouldn't cause EBADF, because socket won't be closed yet, but I see no reason to perform unnecessary work.
1 parent 2e0ae94 commit 24788e3

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

cassandra/io/libevreactor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ def close(self):
321321
self.connected_event.set()
322322

323323
def handle_write(self, watcher, revents, errno=None):
324+
if self.is_closed:
325+
return
324326
if revents & libev.EV_ERROR:
325327
if errno:
326328
exc = IOError(errno, os.strerror(errno))
@@ -362,6 +364,8 @@ def handle_write(self, watcher, revents, errno=None):
362364
return
363365

364366
def handle_read(self, watcher, revents, errno=None):
367+
if self.is_closed:
368+
return
365369
if revents & libev.EV_ERROR:
366370
if errno:
367371
exc = IOError(errno, os.strerror(errno))

0 commit comments

Comments
 (0)