A suspicious code in PQconnectPoll()

From: "Matsumura, Ryo" <matsumura(dot)ryo(at)jp(dot)fujitsu(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: A suspicious code in PQconnectPoll()
Date: 2019-07-19 05:07:04
Message-ID: 03040DFF97E6E54E88D3BFEE5F5480F74AC1541C@G01JPEXMBYT04
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

I find a suspicious code in libpq:PQconnectPoll(). I think it should be
fixed, but I could not produce a concrete problem.
What do you think about it?

I understand that PQconnectPoll() returns PGRES_POLLING_WRITING or
PGRES_POLLING_READ until state machine reaches terminal state(OK or BAD).
The return value indicates for users which event they should wait for
before next PQconnectPoll().
But PQconnectPoll() calls PQsendQuery("SHOW transaction_read_only")
in CONNECTION_AUTH_OK without returning PGRES_POLLING_WRITING before.

My idea is as following:

case CONNECTION_AWAITING_RESPONSE:
receive authetication OK, transit state machine to AUTH_OK and
return PGRES_POLLING_READING.

case CONNECTION_AUTH_OK:
clear any data from backend using PQisBusy(), transit to
CHECK_WRITABLE_STARTED(new state!), and return PGRES_POLLING_WRITING.

case CONNECTION_CHECK_WRITABLE_STARTED (new state!):
call PQsendQuery("SHOW transaction_read_only"), and transit to
CONNECTION_CHECK_WRITABLE, and return CONNECTION_CHECK_READING.

Regards
Ryo Matsumura

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2019-07-19 05:08:30 Compiler warnings with MinGW
Previous Message Жарков Роман 2019-07-19 05:00:37 Re: Intermittent pg_ctl failures on Windows