libpq calls blocking recv when it could not send data enough. - Mailing list pgsql-hackers

From matsumura.ryo@fujitsu.com
Subject libpq calls blocking recv when it could not send data enough.
Date
Msg-id OSAPR01MB5027EBEB735E9878AC81EB34E8490@OSAPR01MB5027.jpnprd01.prod.outlook.com
Whole thread Raw
List pgsql-hackers
Hi all

Libpq may be blocked by recv without checking data arrival
when libpq could not send data enough.
I think it should check by pqReadReady() for avoiding blocking.

  Note: I didn't encounter any issue that the pqReadData is blocked.

[src/interfaces/libpq/fe-misc.c]
  pqSendSome(PGconn *conn, int len)
            :
        sent = pqsecure_write(conn, ptr, Min(len, 65536));
        if (sent < 0)
            :
        else
        {
            len -= sent;
        }
        if (len > 0)
        {
            if (pqReadData(conn) < 0)    // read without checking

Must the pqReadData() return without blocking if it could not send enough?
It may be 'yes', but I think there is no guarantee that there is some data
and pqReadData() is not blocked.

I think the following is better. How about it?
<           if (pqReadData(conn) < 0)
>           if (pqReadReady(conn) && pqReadData(conn) < 0)

Regards
Ryo Matsumura



pgsql-hackers by date:

Previous
From: Antonin Houska
Date:
Subject: Re: Attempt to consolidate reading of XLOG page
Next
From: Konstantin Knizhnik
Date:
Subject: Re: Why overhead of SPI is so large?