pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Cc: Dave Vitek <dvitek@grammatech.com>
Subject: Re: Fwd: race in pg_ctl start -w
Date: Thu, 11 Oct 2012 21:59:31 +0300
Message-ID: <50771713.8000908@vmware.com> (raw)
In-Reply-To: <22107.1349976592@sss.pgh.pa.us>
References: <5076F626.2090404@grammatech.com>
	<5076FF23.6020704@iki.fi>
	<22107.1349976592@sss.pgh.pa.us>

On 11.10.2012 20:29, Tom Lane wrote:
> Heikki Linnakangas<hlinnaka@iki.fi>  writes:
>> A straightforward fix would be to just allocate one large-enough buffer
>> to begin with, e.g 8k, and read the whole file in one go. I'll write up
>> a patch for that.
>
> This makes the readfile function very usage-specific though.  The fix
> I was thinking about was to modify the second loop to force it to fall
> out once the predetermined number of lines had been read.
>
> Or maybe we should use just one loop with realloc, instead of reading
> the file twice.

Hmm, starting with 9.3, postmaster can not only create and append to the 
end of file, it can also inject a line in the middle, shifting the 
following lines forwards. In theory, if a new line is injected into the 
middle of the file between fgets() calls, readfile() could read part of 
the same line twice. Not sure what consequences that could have; pg_ctl 
might try to connect to wrong address or socket directory.

Although in practice, fgets() is buffered, and the buffer is probably 
large enough to hold the whole file, so it probably gets slurped into 
memory as one unit anyway. Then again, I don't think read/write on a 
file is guaranteed to be atomic either, so I guess there's always the 
theoretical possibility of a partial read.

This makes me a bit uncomfortable with the 9.3 change that 
postmaster.pid file is no longer strictly append-only (commit c9b0cbe9). 
Could we delay appending the socket directory and listen address 
information to the file until we know both, and then append both in one 
call after that?

Gah, how can a trivial thing like this be so complicated..

- Heikki




view thread (8+ messages)  latest in thread

Message-ID: <50771713.8000908@vmware.com>
Permalink:  ../50771713.8000908@vmware.com/
Also on:    postgresql.org/message-id/50771713.8000908@vmware.com

 · 

reply

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-bugs@postgresql.org
  Cc: hlinnakangas@vmware.com, tgl@sss.pgh.pa.us, dvitek@grammatech.com
  Subject: Re: Fwd: race in pg_ctl start -w
  In-Reply-To: <50771713.8000908@vmware.com>
  References: <5076F626.2090404@grammatech.com> <5076FF23.6020704@iki.fi> <22107.1349976592@sss.pgh.pa.us> <50771713.8000908@vmware.com>

* 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