FSX/momoko — Issue #11: Momoko doesn't recover from lost connections
Author: cwells
Created: 2012-01-10 04:14:44+00:00
State: open

Came across an opportunity to restart PostgreSQL and did so. My Tornado app ceased functioning and did not recover. Logs reveal the following exception:

Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/tornado/web.py", line 1045, in wrapper
return method(self, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/tornado/gen.py", line 91, in wrapper
Runner(gen).run()
File "/usr/lib/python2.6/site-packages/tornado/gen.py", line 318, in run
self.yield_point.start(self)
File "/usr/lib/python2.6/site-packages/tornado/gen.py", line 207, in start
self.func(*self.args, **self.kwargs)
File "/usr/lib/python2.6/site-packages/momoko/clients.py", line 125, in execute
self._pool.new_cursor('execute', (operation, parameters), callback)
File "/usr/lib/python2.6/site-packages/momoko/pools.py", line 215, in new_cursor
cursor = connection.cursor()
File "/usr/lib/python2.6/site-packages/psycopg2/extras.py", line 116, in cursor
return _connection.cursor(self, cursor_factory=DictCursor)
InterfaceError: connection already closed

Given that Momoko maintains a pool of connections, catching and recovering from this in client code would be difficult.