Description
Hi,
While working on another issue, identified a memory leak in pg_stat_monitor specifically occurring when commands are invoked via the SPI infrastructure within a Background Worker.
The root cause appears to be in the cleanup callback registration. https://github.com/percona/pg_stat_monitor/blob/main/pg_stat_monitor.c#L398
The current logic only registers the cleanup callback if MessageContext is valid. However, when executing via SPI in a Background Worker, MessageContext is typically unavailable.
Consequently, the cleanup function is never triggered, leading to a memory leak.
Attaching the sample contrib which can be used to identify the issue, just need to install the module and add entry in shared_preload_library.
Can you please check this?
spi_sample.patch
Expected Results
N/A
Actual Results
N/A
Version
Postgres 18, pg_stat_monitor 2.3
Steps to reproduce
No response
Relevant logs
Code of Conduct
Description
Hi,
While working on another issue, identified a memory leak in pg_stat_monitor specifically occurring when commands are invoked via the SPI infrastructure within a Background Worker.
The root cause appears to be in the cleanup callback registration. https://github.com/percona/pg_stat_monitor/blob/main/pg_stat_monitor.c#L398
The current logic only registers the cleanup callback if MessageContext is valid. However, when executing via SPI in a Background Worker, MessageContext is typically unavailable.
Consequently, the cleanup function is never triggered, leading to a memory leak.
Attaching the sample contrib which can be used to identify the issue, just need to install the module and add entry in shared_preload_library.
Can you please check this?
spi_sample.patch
Expected Results
N/A
Actual Results
N/A
Version
Postgres 18, pg_stat_monitor 2.3
Steps to reproduce
No response
Relevant logs
Code of Conduct