clientauth: nonexistent pgtle.clientauth_db_name causes indefinite login hang
- Dominant language
- C
- Stars
- 410
- Forks
- 41
- Avg merge
- 18h 17m
- Merged PRs (30d)
- 2
Description
## Description
If `pgtle.clientauth_db_name` names a database that does not exist, every login hangs forever. The clientauth background workers FATAL on startup, the postmaster respawns them once per second, and `clientauth_hook` waits on a shared-memory rendezvous no live worker ever completes. The GUC is `PGC_POSTMASTER`, so no one can log in to fix it.
## Steps to reproduce
1. Fresh cluster with `pg_tle` in `shared_preload_libraries`.
1. Set `pgtle.enable_clientauth = 'on'` and `pgtle.clientauth_db_name = 'ghost_db_does_not_exist'`.
1. Restart, then run `psql -c 'SELECT 1'`.
## Expected outcome
Connection succeeds (matching the existing "pg_tle not installed" fallback under `on`), or is cleanly rejected under `require`.
## Actual outcome
`psql` hangs indefinitely. Killed by `timeout 10` with exit 124 and no output.
## Analysis
Have each worker bump a `workers_ready` counter after `BackgroundWorkerInitializeConnection()` succeeds. `clientauth_hook` waits briefly on it before enqueuing, and on timeout falls back to `can_allow_without_executing` / `can_reject_without_executing`.
### Logs
```
FATAL: database "ghost_db_does_not_exist" does not exist
LOG: background worker "pg_tle_clientauth worker" (PID ...) exited with exit code 1
[repeats every second, forever]
```
Contributor guide
Research direction
Reproduce the hang with the listed cluster settings and `timeout 10 psql -c 'SELECT 1'`. Trace `clientauth_hook`, the clientauth workers, `BackgroundWorkerInitializeConnection()`, and the `can_allow_without_executing`/`can_reject_without_executing` fallbacks; done means the nonexistent database no longer causes an indefinite login hang and `on` and `require` follow their stated outcomes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, postgresql
- Domain
- authentication, databases, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100