| From: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | [oauth] Bug: when is shutdown_cb called? |
| Date: | 2026-02-18 12:50:33 |
| Message-ID: | CAN4CZFOuMb_gnLvCwRdMybg_k8WRNJTjcij+PoQkuQHDUzxGWg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hello
From the documentation[1]:
> The shutdown_cb callback is executed when the backend process associated with the connection exits. If the validator module has any allocated state, this callback should free it to avoid resource leaks.
But it actually gets called when the memory context used during
authentication is cleaned up, immediately after authentication
completes.
I attached a patch that moves it to the actual backend exit, but I'm
not sure if this is the good approach.
The advantages: things like expiration checks[2], or repeated
validation in the future when we implement token refresh need a
working validator state, which means either we have to call
startup/shutdown multiple times, or keep the context. It also behaves
exactly like how the 18.x documentation explains it.
The disadvantages:
1. This is just a shmem exit hook, a validator could register it in
_PG_init anyway
2. The current memory context during the startup / validate callbacks
wasn't TopMemoryContext, so I changed that in the patch. Otherwise
anything allocated in them wouldn't exist in shutdown, creating all
kinds of bugs, as that would be way too easy to overlook.
Maybe we should just fix the documentation instead?
[1] : https://www.postgresql.org/docs/current/oauth-validator-callbacks.html#OAUTH-VALIDATOR-CALLBACK-SHUTDOWN
[2] : https://www.postgresql.org/message-id/CAER375PhG5an%3Dp1%3D6QS6vWi%3DBHxR%2BViJmYPDkkEtpgVsfCcu_w%40mail.gmail.com
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Oauth-validator-shutdown_cb-should-be-called-at-exit.patch | application/octet-stream | 4.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andy Pogrebnoi | 2026-02-18 13:26:24 | Re: Lowering the default wal_blocksize to 4K |
| Previous Message | Ilia Evdokimov | 2026-02-18 12:48:36 | Re: Hash-based MCV matching for large IN-lists |