diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml index 92057006c930..dc7786fff423 100644 --- a/.cirrus.tasks.yml +++ b/.cirrus.tasks.yml @@ -29,7 +29,7 @@ env: MTEST_ARGS: --print-errorlogs --no-rebuild -C build PGCTLTIMEOUT: 120 # avoids spurious failures during parallel tests TEMP_CONFIG: ${CIRRUS_WORKING_DIR}/src/tools/ci/pg_ci_base.conf - PG_TEST_EXTRA: kerberos ldap ssl libpq_encryption load_balance oauth + PG_TEST_EXTRA: kerberos ldap ssl libpq_encryption load_balance oauth tcp # What files to preserve in case tests fail diff --git a/src/interfaces/libpq/fe-cancel.c b/src/interfaces/libpq/fe-cancel.c index 8c7c198a5307..826b8f882999 100644 --- a/src/interfaces/libpq/fe-cancel.c +++ b/src/interfaces/libpq/fe-cancel.c @@ -137,6 +137,8 @@ PQcancelCreate(PGconn *conn) goto oom_error; originalHost = conn->connhost[conn->whichhost]; + cancelConn->connhost[0].type = originalHost.type; + if (originalHost.host) { cancelConn->connhost[0].host = strdup(originalHost.host); diff --git a/src/test/modules/libpq_pipeline/meson.build b/src/test/modules/libpq_pipeline/meson.build index 3fd70a04a38d..9edf6c0a22b5 100644 --- a/src/test/modules/libpq_pipeline/meson.build +++ b/src/test/modules/libpq_pipeline/meson.build @@ -26,6 +26,7 @@ tests += { 'tap': { 'tests': [ 't/001_libpq_pipeline.pl', + 't/002_tcp.pl', ], 'deps': [libpq_pipeline], }, diff --git a/src/test/modules/libpq_pipeline/t/002_tcp.pl b/src/test/modules/libpq_pipeline/t/002_tcp.pl new file mode 100644 index 000000000000..64902a1a9c2e --- /dev/null +++ b/src/test/modules/libpq_pipeline/t/002_tcp.pl @@ -0,0 +1,45 @@ + +# Copyright (c) 2021-2025, PostgreSQL Global Development Group + +use strict; +use warnings FATAL => 'all'; + +use PostgreSQL::Test::Utils; +use Test::More; + +# Force test nodes to begin in TCP mode. +# Use an INIT block so it runs after the BEGIN block in Utils.pm. + +INIT { $PostgreSQL::Test::Utils::use_unix_sockets = 0; } + +use PostgreSQL::Test::Cluster; + +if (!$ENV{PG_TEST_EXTRA} || $ENV{PG_TEST_EXTRA} !~ /\btcp\b/) +{ + plan skip_all => + 'Potentially unsafe test TCP not enabled in PG_TEST_EXTRA'; +} + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +# Don't let PGHOST interfere with these tests. +delete $ENV{PGHOST}; + +my @cases = ( + $node->connstr('postgres') . " max_protocol_version=latest", + $node->connstr('postgres') . " max_protocol_version=3.0", + "hostaddr=127.0.0.1 port=" . $node->port); + +foreach my $c (@cases) +{ + # Don't use $node->command_ok(); it overrides PGHOST too. + command_ok( + [ 'libpq_pipeline', 'cancel', $c ], + "libpq_pipeline cancel, connstr: " . $c); +} + +$node->stop('fast'); + +done_testing();