This project is archived and is in readonly mode.
Async connection blocks when server unavailable
Reported by Adam Petrovic | February 24th, 2014 @ 10:01 AM
not sure if this is psycopg2's fault but my script blocks when connecting to unavailable server (or when i drop outgoing connections to port 5432 for testing puposes).
Here's gdb stack trace:
#0 0x00007ffff6eda308 in poll () from /lib64/libc.so.6 #1 0x00007fffedad101f in pqSocketPoll (conn=0x7c43d0, forRead=1, forWrite=1, end_time=-1) at fe-misc.c:1088 #2 pqSocketCheck (conn=0x7c43d0, forRead=1, forWrite=1, end_time=-1) at fe-misc.c:1030 #3 0x00007fffedad10a0 in pqWaitTimed (forRead=<value optimized out>, forWrite=<value optimized out>, conn=0x7c43d0, finish_time=<value optimized out>) at fe-misc.c:962 #4 0x00007fffedad1510 in pqSendSome (conn=0x7c43d0, len=8) at fe-misc.c:896 #5 0x00007fffedac9f86 in pqPacketSend (conn=0x7c43d0, pack_type=<value optimized out>, buf=0x7fffffffb3a4, buf_len=4) at fe-connect.c:3324 #6 0x00007fffedacbce3 in PQconnectPoll (conn=0x7c43d0) at fe-connect.c:1976 #7 0x00007fffedcfa569 in conn_poll_connecting (self=0x7c32d0) at psycopg/connection_int.c:648 #8 conn_poll (self=0x7c32d0) at psycopg/connection_int.c:877 #9 0x00007fffedcfb6ad in psycoconn_poll (self=<value optimized out>) at psycopg/connection_type.c:850
A checked psycopg2 and libpq source and it looks like the problem is that psycopg2's conn_poll calls _conn_poll_connecting before setting async flag on connection so libpq's pqSendSome thinks connection is in blocking mode.
Thanks for response.
Comments and changes to this ticket
Hello, thank you for the report.
Can you test with the code in the branch "ticket-194" in my repos?
Thank you very much.
Great, script does not block anymore. Now connection.poll() throws
OperationalError: could not send SSL negotiation packet: Resource temporarily unavailable
OperationalError: could not send startup packet: Resource temporarily unavailable
Thanks for quick fix.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
WARNING: the informations in this tracker are archived. Please submit new tickets or comments to the new tracker.
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.