You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
Close pool while invoking Connection.execute, the future returned by Connection.execute will never resolve.
Anyone can reproduce this issue by doing this:
conn=yieldself.db.getconn(False)
yieldconn.execute("BEGIN;")
cursor=yieldconn.execute(" \ DECLARE serv_cur CURSOR FOR \ SELECT * FROM some_table;")
cursor_future=conn.execute("FETCH 2000 FROM serv_cur;")
#at some where of our program, #we close the connection through Pool.close() or just conn.close() like this:conn.close()
#then our program will stuck at following line forevercursor=yieldcursor_futureresult=cursor.fetchall()
yieldconn.execute("CLOSE serv_cur;")
yieldconn.execute("COMMIT;")
The possible solution
In Connection.execute(),Connection.callproc() and Connection.connect()
defexecute(self,
operation,
parameters=(),
cursor_factory=None):
#......other code#before return future, save the last oneassertself.current_futureisNone, "can not concurrently execute on same connection"self.current_future=futurereturnfuture
In Connection._io_callback()
def_io_callback(self, future, result, fd=None, events=None):
try:
state=self.connection.poll()
except (psycopg2.Warning, psycopg2.Error) aserror:
self.ioloop.remove_handler(self.fileno)
future.set_exc_info(sys.exc_info())
#clear last futureself.current_future=Noneelse:
try:
ifstate==POLL_OK:
self.ioloop.remove_handler(self.fileno)
future.set_result(result)
#clear last futureself.current_future=Noneelifstate==POLL_READ:
self.ioloop.update_handler(self.fileno, IOLoop.READ)
elifstate==POLL_WRITE:
self.ioloop.update_handler(self.fileno, IOLoop.WRITE)
else:
future.set_exception(psycopg2.OperationalError("poll() returned %s"%state))
#clear last futureself.current_future=NoneexceptIOError:
# Can happen when there are quite a lof of outstanding# requests. See https://github.com/FSX/momoko/issues/127self.ioloop.remove_handler(self.fileno)
future.set_exception(psycopg2.OperationalError("IOError on socker"))
#clear last futureself.current_future=None
Close pool while invoking Connection.execute, the future returned by Connection.execute will never resolve.
Anyone can reproduce this issue by doing this:
The possible solution
In
Connection.execute()
,Connection.callproc()
andConnection.connect()
In
Connection._io_callback()
In Connection.close()
The text was updated successfully, but these errors were encountered: