Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ static void _close_pgsql_plink(zend_resource *rsrc)

static void _php_pgsql_notice_handler(void *l, const char *message)
{
if (l == NULL) {
/* This connection does not currently have a valid context, ignore this notice */
return;
}
if (PGG(ignore_notices)) {
return;
}
Expand Down Expand Up @@ -360,6 +364,9 @@ static int _rollback_transactions(zval *el)

link = (PGconn *) rsrc->ptr;

/* unset notice processor */
Copy link
Member

Choose a reason for hiding this comment

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

nit:

if (!PGG(ignore_notices)) {
    PQsetNoticeProcessor(link, _php_pgsql_notice_handler, NULL);
}

wdyt ?

Copy link
Member

Choose a reason for hiding this comment

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

or possibly fetching the actual handler -> checking that is _php_pgsql_notice_handler -> unsetting it if yes

Copy link
Contributor Author

@MagicalTux MagicalTux Aug 15, 2025

Choose a reason for hiding this comment

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

If ignore_notices (pgsql.ignore_notice without a s) is changed at runtime there is a risk we could have set the callback but fail to unset it. To be quite honest I am not sure if that's a risk at all, however setting it to a no-op should be safe either way.

The best way would be of course to check if we did set the callback by either storing a flag somewhere, or as an alternative check if the current callback is ours with:

if (PQsetNoticeProcessor(link, NULL, NULL) == _php_pgsql_notice_handler) {
    PQsetNoticeProcessor(link, _php_pgsql_notice_handler, NULL);
}

Copy link
Member

Choose a reason for hiding this comment

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

yes

or possibly fetching the actual handler -> checking that is _php_pgsql_notice_handler -> unsetting it if yes

PQsetNoticeProcessor(link, _php_pgsql_notice_handler, NULL);

if (PQsetnonblocking(link, 0)) {
php_error_docref("ref.pgsql", E_NOTICE, "Cannot set connection to blocking mode");
return -1;
Expand Down
Loading