Re: EXEC_BACKEND vs bgworkers without BGWORKER_SHMEM_ACCESS

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: EXEC_BACKEND vs bgworkers without BGWORKER_SHMEM_ACCESS
Date: 2021-08-02 14:54:15
Message-ID: CA+Tgmobjwpa5qysUdxWRm3pxai1NznYzEpAvStNNdO=Ptkt+4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Aug 2, 2021 at 2:51 AM Andres Freund <andres(at)anarazel(dot)de> wrote:
> which presents a problem: We've initialized all kind of references to shared
> memory, own a PGPROC, but have detached from shared memory.
>
> In practice this will lead pretty quickly to a segfault, because process exit
> will run proc_exit callbacks, which in turn will try to do a ProcKill(). Or
> logging dereferences MyProc, or ...
>
> It seems the above code block would need to at least do shmem_exit() before
> the PGSharedMemoryDetach()?
>
> This code has been introduced in
>
> commit 4d155d8b08fe08c1a1649fdbad61c6dcf4a8671f
> Author: Robert Haas <rhaas(at)postgresql(dot)org>
> Date: 2014-05-07 14:54:43 -0400
>
> Detach shared memory from bgworkers without shmem access.
>
> Since the postmaster won't perform a crash-and-restart sequence
> for background workers which don't request shared memory access,
> we'd better make sure that they can't corrupt shared memory.
>
> Patch by me, review by Tom Lane.
>
> but before that things were just slightly differently broken...

If you're saying that this code has been 100% broken for 7 years and
nobody's noticed until now, then that suggests that nobody actually
uses non-shmem-connected bgworkers. I sort of hate to give up on that
concept but if we've really gone that many years without anyone
noticing obvious breakage then maybe we should.

--
Robert Haas
EDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Drouvot, Bertrand 2021-08-02 14:56:44 Re: Minimal logical decoding on standbys
Previous Message Robert Haas 2021-08-02 14:48:08 Re: Background writer and checkpointer in crash recovery