Skip to content

fix: gracefully handle uninitialized PgLwLock in Docker#28

Merged
YuweiXiao merged 1 commit intomainfrom
worktree-fix-pglwlock-init
Mar 14, 2026
Merged

fix: gracefully handle uninitialized PgLwLock in Docker#28
YuweiXiao merged 1 commit intomainfrom
worktree-fix-pglwlock-init

Conversation

@YuweiXiao
Copy link
Collaborator

Summary

  • Root cause: 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 ERROR: PgLwLock was not initialized.
  • Rust fix: Added SHM_AVAILABLE AtomicBool flag checked by process_shared_preload_libraries_in_progress in _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. Emits WARNING at load time and NOTICE on reads.
  • Docker fix: Added ALTER SYSTEM SET shared_preload_libraries = 'pg_duckdb,pg_ducklake,pg_duckpipe' in the init script — writes to postgresql.auto.conf which always takes precedence over postgresql.conf and conf.d/ settings. Also updated the postgresql.conf.sample line to include pg_ducklake.

Test plan

  • make installcheck — all 30 regression tests pass
  • Docker quick start: docker run, connect, call SELECT * FROM duckpipe.status() — should return results (not crash)
  • Docker quick start: verify SHOW shared_preload_libraries includes pg_duckdb,pg_ducklake,pg_duckpipe
  • Manual test without shared_preload_libraries: CREATE EXTENSION pg_duckpipe then SELECT * FROM duckpipe.status() — should return empty results with NOTICE (not crash)

🤖 Generated with Claude Code

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>
@YuweiXiao YuweiXiao merged commit 89a7440 into main Mar 14, 2026
7 checks passed
@YuweiXiao YuweiXiao deleted the worktree-fix-pglwlock-init branch March 14, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant