Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3631612

Browse files
committed
psql: Fix assertion failures with pipeline mode
A correct cocktail of COPY FROM, SELECT and/or DML queries and\syncpipeline was able to break the logic in charge of discardingresults of a pipeline, done in discardAbortedPipelineResults(). Suchsequence make the backend generate a FATAL, due to a protocolsynchronization loss.This problem comes down to the fact that we did not consider the case oflibpq returning a PGRES_FATAL_ERROR when discarding the results of anaborted pipeline. The discarding code is changed so as this resultstatus is handled as a special case, with the caller ofdiscardAbortedPipelineResults() being responsible for consuming theresult.A couple of tests are added to cover the problems reported, bringing aninteresting gain in coverage as there were no tests in the tree coveringthe case of protocol synchronization loss.Issue introduced by41625ab.Reported-by: Alexander Kozhemyakin <a.kozhemyakin@postgrespro.ru>Author: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>Co-authored-by: Michael Paquier <michael@paquier.xyz>Discussion:https://postgr.es/m/ebf6ce77-b180-4d6b-8eab-71f641499ddf@postgrespro.ru
1 parent923ae50 commit3631612

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

‎src/bin/psql/common.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,23 @@ discardAbortedPipelineResults(void)
14781478
*/
14791479
returnres;
14801480
}
1481+
elseif (res!=NULL&&result_status==PGRES_FATAL_ERROR)
1482+
{
1483+
/*
1484+
* Found a FATAL error sent by the backend, and we cannot recover
1485+
* from this state. Instead, return the last result and let the
1486+
* outer loop handle it.
1487+
*/
1488+
PGresult*fatal_resPG_USED_FOR_ASSERTS_ONLY;
1489+
1490+
/*
1491+
* Fetch result to consume the end of the current query being
1492+
* processed.
1493+
*/
1494+
fatal_res=PQgetResult(pset.db);
1495+
Assert(fatal_res==NULL);
1496+
returnres;
1497+
}
14811498
elseif (res==NULL)
14821499
{
14831500
/* A query was processed, decrement the counters */

‎src/bin/psql/t/001_basic.pl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,45 @@ sub psql_fails_like
483483
my$c4 = slurp_file($g_file);
484484
like($c4,qr/foo.*bar/s);
485485

486+
# Tests with pipelines. These trigger FATAL failures in the backend,
487+
# so they cannot be tested via SQL.
488+
$node->safe_psql('postgres','CREATE TABLE psql_pipeline()');
489+
my$log_location =-s$node->logfile;
490+
psql_fails_like(
491+
$node,
492+
qq{\\startpipeline
493+
COPY psql_pipeline FROM STDIN;
494+
SELECT 'val1';
495+
\\syncpipeline
496+
\\getresults
497+
\\endpipeline},
498+
qr/server closed the connection unexpectedly/,
499+
'protocol sync loss in pipeline: direct COPY, SELECT, sync and getresult'
500+
);
501+
$node->wait_for_log(
502+
qr/FATAL: .*terminating connection because protocol synchronization was lost/,
503+
$log_location);
504+
505+
psql_fails_like(
506+
$node,
507+
qq{\\startpipeline
508+
COPY psql_pipeline FROM STDIN\\bind\\sendpipeline
509+
SELECT 'val1'\\bind\\sendpipeline
510+
\\syncpipeline
511+
\\getresults
512+
\\endpipeline},
513+
qr/server closed the connection unexpectedly/,
514+
'protocol sync loss in pipeline: bind COPY, SELECT, sync and getresult');
515+
516+
# This time, test without the \getresults.
517+
psql_fails_like(
518+
$node,
519+
qq{\\startpipeline
520+
COPY psql_pipeline FROM STDIN;
521+
SELECT 'val1';
522+
\\syncpipeline
523+
\\endpipeline},
524+
qr/server closed the connection unexpectedly/,
525+
'protocol sync loss in pipeline: COPY, SELECT and sync');
526+
486527
done_testing();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp