fix: gracefully handle uninitialized PgLwLock in Docker#28
Merged
Conversation
PgLwLock is only initialized when the extension is loaded via shared_preload_libraries. If the base Docker image overrides shared_preload_libraries (e.g. via postgresql.auto.conf or conf.d/), pg_duckpipe is not preloaded and status()/worker_status()/metrics() crash with "PgLwLock was not initialized". - Add SHM_AVAILABLE AtomicBool flag set during _PG_init only when process_shared_preload_libraries_in_progress is true - Guard all SHM access functions to return defaults/no-op when the lock is unavailable instead of panicking - Emit WARNING at extension load and NOTICE on SHM reads when not in shared_preload_libraries - Add ALTER SYSTEM in Docker init script to ensure shared_preload_libraries is set in postgresql.auto.conf (overrides any conf.d/ or postgresql.conf settings) - Include pg_ducklake in shared_preload_libraries alongside pg_duckdb and pg_duckpipe Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
PgLwLockis only initialized when the extension is loaded viashared_preload_libraries. If the base Docker image overridesshared_preload_libraries(e.g. viapostgresql.auto.conforconf.d/),pg_duckpipeis not preloaded andstatus()/worker_status()/metrics()crash withERROR: PgLwLock was not initialized.SHM_AVAILABLEAtomicBool flag checked byprocess_shared_preload_libraries_in_progressin_PG_init. All SHM access functions (read_shmem_table_metrics,read_shmem_group_metrics,write_shmem_metrics,clear_shmem_table_slot,clear_shmem_group_slot) now return defaults/no-op when the lock is unavailable. EmitsWARNINGat load time andNOTICEon reads.ALTER SYSTEM SET shared_preload_libraries = 'pg_duckdb,pg_ducklake,pg_duckpipe'in the init script — writes topostgresql.auto.confwhich always takes precedence overpostgresql.confandconf.d/settings. Also updated thepostgresql.conf.sampleline to includepg_ducklake.Test plan
make installcheck— all 30 regression tests passdocker run, connect, callSELECT * FROM duckpipe.status()— should return results (not crash)SHOW shared_preload_librariesincludespg_duckdb,pg_ducklake,pg_duckpipeshared_preload_libraries:CREATE EXTENSION pg_duckpipethenSELECT * FROM duckpipe.status()— should return empty results with NOTICE (not crash)🤖 Generated with Claude Code