Comments (3)
You are right. However it looks like the issue is even deeper - if I call Pool.close()
in the middle operation, the retry logic will reestablish the connection, so at the end Pool.close()
does not do its jobs well.
I think the retry logic should not act if Pool.closed
is true; and yes, Pool.close()
should not empty connection sets .
Also I wonder whether public API should assert not self.closed
before doing anything.
What do you think?
from momoko.
@haizaar , I agree with your concern. I tried a few changes in momoko to make it work right under any closing time, some changes like:
- Put close check in Connection.execute and Connection.callproc at beginning, raise if disconnected.
- Catch exceptions at
execute()
in Connection.transaction [connection.L876, connection.L879], then put sys.exc_info() intotransaction_future
. In _rollback(), apply the same changes. - In Pool.getconn, check Pool.closed flag before doing anything, if it's closed, raise. And never use Pool.connect second time, it will increase connections. or change it a little bit:
def connect(self):
future = Future()
assert self.conns.total <= self.size, "total should not greater than size"
size = self.size - self.conns.total
#add check here
if 0 == size and self.conns.all_dead:
def on_getconn(fut):
try:
conn = fut.result()
except Exception as error:
future.set_exc_info(sys.exc_info())
else:
future.set_result(self)
self.putconn(conn)
self.ioloop.add_future(self.getconn(), on_getconn)
return future
#change pending count here
pending = [max(size-1, 0)]
def on_connect(fut):
if pending[0]:
pending[0] -= 1
return
# all connection attempts are complete
if self.conns.dead and self.raise_connect_errors:
ecp = PartiallyConnectedError("%s connection(s) failed to connect" % len(self.conns.dead))
future.set_exception(ecp)
else:
future.set_result(self)
log.debug("All initial connection requests complete")
#create connection use altered size
for i in range(size):
self.ioloop.add_future(self._new_connection(), on_connect)
return future
After the changes we made, I prefer to use Pool.getconn at the beginning instead of Pool.conncet, It could make life simple, change connection.L316 in Pool.getconn to:
if self.conns.total:
self.ioloop.add_future(self._reanimate(), on_reanimate_done)
else:
#new db object, and haven't invoked connect(),start with one connection
self.ioloop.add_future(self._new_connection(), on_reanimate_done)
from momoko.
Frankly I'm a bit swamped and hardly will get to work on it until middle next week. If you want to submit PRs with unittests for each of the issues, I'll be happy to review and merge them. Do you want to give it a shot?
from momoko.
Related Issues (20)
- momoko makes IOError in ioloop HOT 3
- Behavior of .execute() wo parameters does not match psycopg2 HOT 1
- code in ConnectionContainer.all_dead conflicts with Pool.putconn HOT 4
- The future returned by Connection.execute will never resolve HOT 1
- How can I run the first sample of momoko HOT 6
- Pool fails to reconnect when using Unix-domain socket (OperationalError: server closed the connection unexpectedly) HOT 18
- Restarting PostgreSQL sometimes causes Pool.getconn() to hang HOT 5
- Momoko Pool trying to use dead connections HOT 3
- Writing tests for tornado app, which uses momoko for postgres DB. HOT 2
- Cannot add momoko HOT 1
- Please help me figure out why this code freezes forever HOT 8
- Any suggestion on how I'd commit/rollback using a connection pool? HOT 3
- when using RealDictCursor, Pool.register_json error HOT 2
- Typo in connection.py (socker instead of socket) HOT 2
- error if trying to connect pool while Postgress is not online HOT 2
- NamedTupleCursor factory test is executed even if MOMOKO_TEST_HSTORE is disabled HOT 1
- Debian packaging HOT 1
- AttributeError: 'Future' object has no attribute 'set_exc_info' HOT 5
- Not worked with python 3.7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from momoko.