Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Async connection blocks when server unavailable

#194

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

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

State: resolved
Milestone: none
Assigned to: nobody

Activity

  1. Daniele Varrazzo
    Daniele Varrazzo

    Hello, thank you for the report.

    Can you test with the code in the branch "ticket-194" in my repos?

    https://github.com/dvarrazzo/psycopg/tree/ticket-194

    Thank you very much.

    February 24th, 2014 @ 12:17 PM

  2. Adam Petrovic
    Adam Petrovic

    Great, script does not block anymore. Now connection.poll() throws

    OperationalError: could not send SSL negotiation packet: Resource temporarily unavailable
    
    for SSL connection and
    OperationalError: could not send startup packet: Resource temporarily unavailable
    
    for unsecured one. I guess thats corrent behaviour.

    Thanks for quick fix.

    February 24th, 2014 @ 02:44 PM

  3. Daniele Varrazzo
    Daniele Varrazzo
    • State changed from new to resolved

    Thank you for the diagnosis: I will mention your contribution in the news (if you don't mind).

    February 24th, 2014 @ 03:10 PM

  4. Adam Petrovic
    Adam Petrovic

    I don't mind, happy to help :)

    February 24th, 2014 @ 03:20 PM