From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@postgreSQL.org
Subject: Order of operations in SubPostmasterMain()
Date: Thu, 29 Sep 2016 15:46:00 -0400
Message-ID: <4157.1475178360@sss.pgh.pa.us> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
I noticed that buildfarm member culicidae, which is running an
EXEC_BACKEND build on Linux, occasionally falls over like this:
FATAL: could not reattach to shared memory (key=6280001, addr=0x7fa9df845000): Invalid argument
That's probably because Andres failed to disable ASLR on that machine,
but the exact cause isn't too important right now. What I'm finding
distressing is that that message doesn't show up on the client side,
making it look like a postmaster crash:
inline patch 1: /home/andres/build/buildfarm-culicidae/HEAD/pgsql.build/contrib/intarray/results/_int.out (+3/-1 lines) download inline-1.patch*** /home/andres/build/buildfarm-culicidae/HEAD/pgsql.build/../pgsql/contrib/intarray/expected/_int.out 2016-09-15 22:02:39.512951557 +0000
--- /home/andres/build/buildfarm-culicidae/HEAD/pgsql.build/contrib/intarray/results/_int.out 2016-09-29 17:52:56.921948612 +0000
***************
*** 1,568 ****
! .... lots ...
--- 1,3 ----
! psql: server closed the connection unexpectedly
! This probably means the server terminated abnormally
! before or while processing the request.
The reason we don't see anything is that backend libpq hasn't been
initialized yet, so it won't send the ereport message to the client.
The original design of SubPostmasterMain() intended that such cases
would be reported, because it runs BackendInitialize (which calls
pq_init()) before CreateSharedMemoryAndSemaphores (which is where
the reattach used to happen --- the comments at postmaster.c 4730ff
and 4747ff reflect this expectation). We broke it when we added
the earlier reattach call at lines 4669ff.
We could probably refactor things enough so that we do pq_init()
before PGSharedMemoryReAttach(). It would be a little bit ugly,
and it would fractionally increase the chance of a reattach failure
because pq_init() palloc's a few KB worth of buffers. I'm not quite
sure if it's worth it; thoughts? In any case the mentioned comments
are obsolete and need to be moved/rewritten.
Another thing that I'm finding distressing while I look at this is
the placement of ClosePostmasterPorts(). That needs to happen *early*,
because as long as the child process is holding open the postmaster side
of the postmaster death pipe, we are risking unhappiness. Not only is
it not particularly early, it's after process_shared_preload_libraries()
which could invoke arbitrarily stupid stuff. Whether or not we do
anything about moving pq_init(), I'm thinking we'd better move the
ClosePostmasterPorts() call so that it's done as soon as possible,
probably right after read_backend_variables() which loads the data
it needs.
Comments?
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: Order of operations in SubPostmasterMain()
In-Reply-To: <4157.1475178360@sss.pgh.pa.us>
References: <4157.1475178360@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox