Re: Error: dsa_area could not attach to a segment that has been freed

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Gaddam Sai Ram <gaddamsairam(dot)n(at)zohocorp(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Error: dsa_area could not attach to a segment that has been freed
Date: 2017-09-20 08:55:43
Message-ID: CAEepm=3c4WAtSQG4tAF7Y_VCnO5cKh7KuFYZhpKbwGQOF=dZ4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Sep 20, 2017 at 6:14 PM, Gaddam Sai Ram
<gaddamsairam(dot)n(at)zohocorp(dot)com> wrote:
> Thank you very much! That fixed my issue! :)
> I was in an assumption that pinning the area will increase its lifetime but
> yeah after taking memory context into consideration its working fine!

So far the success rate in confusing people who first try to make
long-lived DSA areas and DSM segments is 100%. Basically, this is all
designed to ensure automatic cleanup of resources in short-lived
scopes.

Good luck for your graph project. I think you're going to have to
expend a lot of energy trying to avoid memory leaks if your DSA lives
as long as the database cluster, since error paths won't automatically
free any memory you allocated in it. Right now I don't have any
particularly good ideas for mechanisms to deal with that. PostgreSQL
C has exception-like error handling, but doesn't (and probably can't)
have a language feature like scoped destructors from C++. IMHO
exceptions need either destructors or garbage collection to keep you
sane. There is a kind of garbage collection for palloc'd memory and
also for other resources like file handles, but if you're using a big
long lived DSA area you have nothing like that. You can use
PG_TRY/PG_CATCH very carefully to clean up, or (probably better) you
can try to make sure that all your interaction with shared memory is
no-throw (note that that means using dsa_allocate_extended(x,
DSA_ALLOC_NO_OOM), because dsa_allocate itself can raise errors). The
first thing I'd try would probably be to keep all shmem-allocating
code in as few routines as possible, and use only no-throw operations
in the 'critical' regions of them, and maybe look into some kind of
undo log of things to free or undo in case of error to manage
multi-allocation operations if that turned out to be necessary.

--
Thomas Munro
http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2017-09-20 09:06:38 Re: Varying results when using merge joins over postgres_fdw vs hash joins
Previous Message Alexander Korotkov 2017-09-20 08:49:35 Re: Index Only Scan support for cube