Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Momoko doesn't recover from lost connections #11

cwells opened this Issue January 09, 2012 · 3 comments

2 participants

Cliff Wells Frank Smit
Cliff Wells

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/", line 1045, in wrapper
    return method(self, *args, **kwargs)
  File "/usr/lib/python2.6/site-packages/tornado/", line 91, in wrapper
  File "/usr/lib/python2.6/site-packages/tornado/", line 318, in run
  File "/usr/lib/python2.6/site-packages/tornado/", line 207, in start
    self.func(*self.args, **self.kwargs)
  File "/usr/lib/python2.6/site-packages/momoko/", line 125, in execute
    self._pool.new_cursor('execute', (operation, parameters), callback)
  File "/usr/lib/python2.6/site-packages/momoko/", line 215, in new_cursor
    cursor = connection.cursor()
  File "/usr/lib/python2.6/site-packages/psycopg2/", 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.

Frank Smit
FSX commented January 10, 2012

Can you try this commit?

It catches the exception, removes the closed connection and check if there is a new one. If there's no connection: create one. And if there is a connection: execute new_cursor again.

Frank Smit
FSX commented January 13, 2012

Did it work? Can I close this?

Cliff Wells

Sorry it took so long to respond. Yes, this appears to work fine. Thanks for the quick fix!

Cliff Wells cwells closed this January 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.