Repository navigation
[REL_2_STABLE] Link postgres_fdw against libpq.so to fix SCRAM disconnect crash - #2494
Merged
tuhaihe merged 2 commits intoDec 4, 2026
Merged
Conversation
yjhjstz
force-pushed
the
fix/postgres-fdw-dynamic-libpq-rel2
branch
from
December 4, 2026 01:59
6dadb83 to
731aaa0
Compare
chenjinbao1989
approved these changes
Dec 4, 2026
gfphoenix78
reviewed
Dec 4, 2026
reshke
approved these changes
Dec 4, 2026
This reverts commit 667f0c3. It would also work without it, in the opposite way, it has two issues: 1, it failed to build on macOS, with an error "ld: unknown option: --exclude-libs=libpq.a" 2, after the 12 merge, it triggers a PostgreSQL's error: "libpq is incorrectly linked to backend functions" (cherry picked from commit ceda5994991c17c57331d84d914478d123a2aa18)
Cloudberry linked libpq.a statically into postgres_fdw and added a copy of src/common/link-canary.c compiled with -DFRONTEND, only to make libpq's "libpq is incorrectly linked to backend functions" check pass. That check was right: libpq was calling the backend's src/common functions. With a SCRAM-authenticated remote server, pg_saslprep() returned a palloc'd password that libpq later passed to free() in scram_free() when the connection was closed. The memory context it came from (typically ExecutorState) was gone by then, so any disconnect crashed the backend: postgres_fdw_disconnect(), ALTER SERVER/USER MAPPING, or a cache reset processed at the start of the next statement. The previous commit links libpq.so dynamically, as Greenplum and upstream do; that is safe since 32cde27 hides the backend's copy of the libpq symbols. libpq.so uses its own frontend src/common and its own link canary, so the copy in postgres_fdw.so is no longer used. Remove it. Fixes apache#2490 (cherry picked from commit df22e82)
yjhjstz
force-pushed
the
fix/postgres-fdw-dynamic-libpq-rel2
branch
from
December 4, 2026 03:38
731aaa0 to
6f55487
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #2492 to REL_2_STABLE. The same two commits are applied with
git cherry-pick -x:libpq.sodynamically. It has the same conflict as on main (the extra-Bsymbolicand aGPDB_13_MERGE_FIXMEcomment), resolved to the Greenplum side.link-canary.oworkaround. This one applied cleanly.Fixes #2490 on the 2.x line. With a SCRAM-authenticated remote server, postgres_fdw crashes the coordinator whenever it closes a cached connection:
postgres_fdw_disconnect*(),ALTER SERVER/ALTER USER MAPPING, or a cache reset processed at the start of the next statement. The cause is the statically linked libpq. It used the backend'spg_saslprep(), so it got a palloc'd password fromExecutorStateand later calledfree()on it inscram_free(). See #2492 for the full analysis.REL_2_STABLE already has 0b80005 (Greenplum #16234), which hides the backend's copy of the libpq symbols, so linking
libpq.sois safe here. 2.1.0 and 2.2.0 include it as well. 2.0.0 does not. Itslibpostgres.sostill exports thePQ*symbols, so dblink with SCRAM crashes there too. Users on 2.0.x should upgrade to a 2.x release that contains this fix.Testing on a demo cluster built from this branch, with the cluster itself as the remote server and a
scram-sha-256role:free(): invalid pointer. One of them is theCREATE FOREIGN TABLEstack from terminated by signal 11 Segmentation fault #2490. With the patch, those paths andpostgres_fdw_disconnect_all()all pass.md5and dblink with SCRAM pass before and after.GPDB #16219: validate scram-sha-256 in postgres_fdwsection ofgp_postgres_fdwalready covers this bug. Without the patch, the backend crashes at itsALTER SERVERstep. With the patch, the section passes. Other parts ofgp_postgres_fdwandmpp_postgres_fdwstill fail because their expected files are stale; that is unchanged by this PR, and these tests are not run in CI.