From de98f2f20d7f98002fd54eee514afc22ea63d344 Mon Sep 17 00:00:00 2001 From: Zaar Hai Date: Sun, 25 Oct 2015 17:15:34 +0200 Subject: [PATCH] Catching IOError. Fixes #127 Under heavy load we get "No such file or directory" error when updating callbacks. I've failed to reproduce it with the tcpproxy setup, so this bugfix is currently not covered with unittest. --- momoko/connection.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/momoko/connection.py b/momoko/connection.py index 9e7607c..79d9ab1 100644 --- a/momoko/connection.py +++ b/momoko/connection.py @@ -703,15 +703,21 @@ def _io_callback(self, future, result, fd=None, events=None): self.ioloop.remove_handler(self.fileno) future.set_exc_info(sys.exc_info()) else: - if state == POLL_OK: + try: + if state == POLL_OK: + self.ioloop.remove_handler(self.fileno) + future.set_result(result) + elif state == POLL_READ: + self.ioloop.update_handler(self.fileno, IOLoop.READ) + elif state == POLL_WRITE: + self.ioloop.update_handler(self.fileno, IOLoop.WRITE) + else: + future.set_exception(psycopg2.OperationalError("poll() returned %s" % state)) + except IOError: + # Can happen when there are quite a lof of outstanding + # requests. See https://github.com/FSX/momoko/issues/127 self.ioloop.remove_handler(self.fileno) - future.set_result(result) - elif state == POLL_READ: - self.ioloop.update_handler(self.fileno, IOLoop.READ) - elif state == POLL_WRITE: - self.ioloop.update_handler(self.fileno, IOLoop.WRITE) - else: - future.set_exception(psycopg2.OperationalError("poll() returned %s" % state)) + future.set_exception(psycopg2.OperationalError("IOError on socker")) def ping(self): """