pgpool2.git / summary / log / commit / refs

commit    181d300de6337fe9a10b60ddbd782aa886b563e9
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Fri Aug 09 10:55:05 2024 +0000

    Fix bug in replication mode and snapshot isolation mode.
    
    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.


src/protocol/pool_proto_modules.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/protocol/pool_proto_modules.c b/src/protocol/pool_proto_modules.c index 7725df65d..e62a3e0bf 100644 --- a/src/protocol/pool_proto_modules.c +++ b/src/protocol/pool_proto_modules.c @@ -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. [parent: 744c96fedbeb]