-
Notifications
You must be signed in to change notification settings - Fork 95
Issue on connect timeout #1
Comments
Confirmed, I have a repro and a test for it now which will allow me to fix it ASAP |
The issue seems to be related to using gevent Python and amysql in interactive mode thus making a sleep which doesn't call the gevent reactor. If I put together a test from this and do gevent.sleep() it all works out. Gonna keep testing |
import amysql cnn.close() |
I'm creating a connection pool for this, I think I need to extending the socket time out duration to have an effective connection pooling |
You should have to call anything but I can't reproduce the issue if I If I do time.sleep() (blocking sleep) or simply wait in the python There's something happening with gevent, it seems as if the first //JT On 2011-06-01 00:35, jsia wrote:
Jonas Tärnström ESN Social Software AB |
I've commited a fix for this bug as far as the repro test goes: |
I am using amysql in production. I implemented a connection pool with amysql, and found that 1 in 50 write requests are failing with RunTimeError Not connected. For now I am having a try except to catch the error and open a new connection to complete the write. A few things to make amysql better:
|
You need to check for the connection if it is still available before you use the connection from the pool. Try to query first then check if it is still usable, if not create a new connection, I think you are experiencing socket timeout, it closes the connection if it has been idle for a period of time |
@jsia so you are suggesting me to check if cnn is connected by calling a query ? or a is_connected() method on it ?
Also is there a way to increase the socket timeout? Because sqlalchemy takes pool_recycle parameter to recycle the connections in the pool. data = cnn.query("DELETE FROM users WHERE ID=%s", (user_id)) |
Hi, What i did was to edit the code Connection.cpp, I think you have to make it configurable if you want flexibility. You can also run a separate tasklet that will monitor your pool or create a map on when was the last time the connection was used, I used the socket id to determine when was the last time the connection was used and set a threshold value, if it surpasses the threshold value then you need to recreate the connection even without checking if its still alive Thanks, From: yashh [mailto:[email protected]] @jsia so you are suggesting me to check if cnn is connected by calling a query ? or a is_connected() method on it ?
Also is there a way to increase the socket timeout? Because sqlalchemy takes pool_recycle parameter to recycle the connections in the pool. data = cnn.query("DELETE FROM users WHERE ID=%s", (user_id)) -- |
I tried this code
import amysql
cnn = amysql.Connection()
cnn.connect(DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME)
wait for > 10 seconds
cnn.close()
cnn = amysql.Connection()
cnn.connect(DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME)
Traceback (most recent call last):
File "", line 1, in
RuntimeError: Connection timed out (0)
It produces an error I have to do connect two times for it to have a reconnect
The text was updated successfully, but these errors were encountered: