Parallel vacuum: avoid dangling shared memory pointers

Started by Bharath Rupireddyabout 2 months ago4 messageshackers

Thread notes

1 note#refactor
hackorum-bot#refactor
hackorum-bot
2 days ago

@global #refactor

#refactor
Jump to latest
#1Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com

Hi,

I noticed that two of the parallel vacuum's shared memory pointers
(VacuumSharedCostBalance and VacuumActiveNWorkers) are not reset on
the error path, leaving them dangling, that is, pointing to a shared
memory segment that is already gone, until the next vacuum runs in the
backend or autovacuum worker. This doesn't cause any issue today, but
IMHO it is good practice to avoid dangling pointers.

Please find the attached patch that sets them to NULL on the error
path (the normal path resets them in
parallel_vacuum_process_all_indexes()).

Thoughts?

--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com

Attachments:

t254190_1
v1-0001-Avoid-dangling-shared-memory-pointers-in-parallel.patchapplication/x-patch; name=v1-0001-Avoid-dangling-shared-memory-pointers-in-parallel.patchDownload+3-1
#2Masahiko Sawada
sawada.mshk@gmail.com
In reply to: Bharath Rupireddy (#1)
Re: Parallel vacuum: avoid dangling shared memory pointers

On Tue, Oct 13, 2026 at 8:31 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

Hi,

I noticed that two of the parallel vacuum's shared memory pointers
(VacuumSharedCostBalance and VacuumActiveNWorkers) are not reset on
the error path, leaving them dangling, that is, pointing to a shared
memory segment that is already gone, until the next vacuum runs in the
backend or autovacuum worker. This doesn't cause any issue today, but
IMHO it is good practice to avoid dangling pointers.

Please find the attached patch that sets them to NULL on the error
path (the normal path resets them in
parallel_vacuum_process_all_indexes()).

Thoughts?

+1 to explicitly clear these variables.

Given that it doesn't cause any problems today, I think we can apply
it only to master.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

#3Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Masahiko Sawada (#2)
Re: Parallel vacuum: avoid dangling shared memory pointers

Hi,

On Wed, Oct 14, 2026 at 1:31 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote:

I noticed that two of the parallel vacuum's shared memory pointers
(VacuumSharedCostBalance and VacuumActiveNWorkers) are not reset on
the error path, leaving them dangling, that is, pointing to a shared
memory segment that is already gone, until the next vacuum runs in the
backend or autovacuum worker....

+1 to explicitly clear these variables.

Given that it doesn't cause any problems today, I think we can apply
it only to master.

Other than keeping the version diff small, I don't have a strong
opinion on back-patching it to PG19, as it doesn't fix a bug. So
applying it on HEAD looks fine to me.

--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com

#4Masahiko Sawada
sawada.mshk@gmail.com
In reply to: Bharath Rupireddy (#3)
Re: Parallel vacuum: avoid dangling shared memory pointers

On Wed, Oct 14, 2026 at 7:19 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

Hi,

On Wed, Oct 14, 2026 at 1:31 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote:

I noticed that two of the parallel vacuum's shared memory pointers
(VacuumSharedCostBalance and VacuumActiveNWorkers) are not reset on
the error path, leaving them dangling, that is, pointing to a shared
memory segment that is already gone, until the next vacuum runs in the
backend or autovacuum worker....

+1 to explicitly clear these variables.

Given that it doesn't cause any problems today, I think we can apply
it only to master.

Other than keeping the version diff small, I don't have a strong
opinion on back-patching it to PG19, as it doesn't fix a bug. So
applying it on HEAD looks fine to me.

I've pushed it to master.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com