This project is archived and is in readonly mode.

#194 ✓resolved
Adam Petrovic

Async connection blocks when server unavailable

Reported by Adam Petrovic | February 24th, 2014 @ 10:01 AM

Hi,

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.

https://github.com/postgres/postgres/blob/master/src/interfaces/lib...

psycopg2: 2.5.2
postgresql-libs: 9.3.2

Thanks for response.
Adam

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
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.

Shared Ticket Bins

Pages