Skip to content

Fix GH-12974: Apache crashes on shutdown when using pg_pconnect() #13032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

nielsdos
Copy link
Member

On ZTS, the global variables are stored in dynamically allocated memory. When the module gets shut down this memory is released. After the module is shut down, only then are the persistent resources cleared. Normally this isn't an issue, but pgsql and odbc refer to the globals to modify some counters, after the globals have been freed.
Fix this by guarding the modification.

We don't have Apache tests unfortunately, but I tested this manually with Valgrind (instructions in the linked issue).

On ZTS, the global variables are stored in dynamically allocated memory.
When the module gets shut down this memory is released. After the module
is shut down, only then are the persistent resources cleared. Normally
this isn't an issue, but pgsql and odbc refer to the globals to modify
some counters, after the globals have been freed.
Fix this by guarding the modification.
@devnexen
Copy link
Member

Looking good ; I noticed oci8 seems to have a similar issue (php_oci_pconnection_list_dtor), up to you if yo wanna update in this PR.

@nielsdos
Copy link
Member Author

Updated. (also fixed a syntax mistake in NTS, oops)

@nielsdos
Copy link
Member Author

Actually looks like oci8 is a little bit more difficult because it accesses the globals in functions that are transitively called too... And also in macros (e.g. PHP_OCI_CALL) Not too sure what clean way to fix it there.

@devnexen
Copy link
Member

gotcha, preferably it would be nice to have odbc/pgsql fixd for the next release, we can always come back to oci8 later if it takes time.

@nielsdos
Copy link
Member Author

gotcha, preferably it would be nice to have odbc/pgsql fixd for the next release, we can always come back to oci8 later if it takes time.

I agree, dropped oci8 change.

Copy link
Member

@devnexen devnexen left a comment

Choose a reason for hiding this comment

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

Thanks for your help.

@nielsdos nielsdos closed this in 77ac1e8 Dec 27, 2023
@nielsdos
Copy link
Member Author

Thanks for your help.

My pleasure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apache crashes on shutdown when using pg_pconnect()
2 participants