Skip to content

Conversation

@bizwark
Copy link
Contributor

@bizwark bizwark commented Apr 18, 2025

This change calls PostmasterIsAliveInternal so that the background worker for these extensions will exit if the postmaster received a SIGKILL signal. This change also includes build changes to verify that the signature of PostmasterIsAliveInternal as called from lib.rs matches what is in the Postgres specified by pg_config, so that if the function signature is ever changed in the future we will fail to build rather than crashing at runtime.

@bizwark bizwark requested a review from hlinnaka April 18, 2025 18:33

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

const _CHECK_SIG: unsafe extern "C" fn() -> bool = PostmasterIsAliveInternal;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? If the signature of PostmasterIsAliveInternal changes, wouldn't you get a compilation error even without this?

@hlinnaka
Copy link

Now that I think about this some more, I think using wait_latch() might be the most straightforward solution. That already exists in pgrx. We don't need to wait on any latch here, but you can use wait_latch() just to sleep. I think you can replace the sleep with wait_latch(), and it will get woken up if the postmaster dies. Or if you use the WL_EXIT_ON_PM_DEATH, it will directly exit the process, which is what we want here I believe.

Sorry I didn't realize that before, I somehow thought that the loop needs to wait on something else at the same time. I didn't realize you could use wait_latch() just to check for postmaster death and/or to replace the sleep.

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.

3 participants