Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Momoko doesn't recover from lost connections #11

Closed
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/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.

Frank Smit
Owner
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
Owner
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.