Skip to content

Commit

Permalink
Fix bug in replication mode and snapshot isolation mode.
Browse files Browse the repository at this point in the history
In replication mode and snapshot isolation mode when a command fishes,
pgpool waits for a ready for query message but forgot that some
commands (for example SET ROLE) produces a parameter status
message. As a result pgpool errors out that other message arrives
before the ready for query message.  Deal with the case when a
parameter status message arrives.

Here is the test case written in pgproto data format.

'P'	""	"SET ROLE TO foo"
'B'	""	""	0	0	0
'E'	""	0
'P'	""	"SELECT 1"
'B'	""	""	0	0	0
'E'	""	0
'S'
'Y'

Backpatch-through: v4.1.
  • Loading branch information
tatsuo-ishii committed Aug 9, 2024
1 parent 744c96f commit 181d300
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/protocol/pool_proto_modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -1480,9 +1480,31 @@ Parse(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend,

kind = pool_read_kind(backend);
if (kind != 'Z')
ereport(ERROR,
(errmsg("unable to parse the query"),
errdetail("invalid read kind \"%c\" returned from backend %d after Sync message sent", kind, i)));
{
/*
* It is possible that parameter status message was sent from
* backend.
*/
if (kind == 'S')
{
if (ParameterStatus(frontend, backend) != POOL_CONTINUE)
ereport(ERROR,
(errmsg("unable to process parameter status message")));

/* expecting ready for query message */
kind = pool_read_kind(backend);
if (kind != 'Z')
ereport(ERROR,
(errmsg("unable to parse the query"),
errdetail("invalid read kind \"%c\" returned from backend after Sync message sent",
kind)));
}
else
ereport(ERROR,
(errmsg("unable to parse the query"),
errdetail("invalid read kind \"%c\" returned from backend after Sync message sent",
kind)));
}

/*
* SYNC message returns "Ready for Query" message.
Expand Down

0 comments on commit 181d300

Please sign in to comment.