Re: Fwd: race in pg_ctl start -w - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Fwd: race in pg_ctl start -w
Date
Msg-id 22107.1349976592@sss.pgh.pa.us
Whole thread Raw
In response to Fwd: race in pg_ctl start -w  (Heikki Linnakangas <hlinnaka@iki.fi>)
Responses Re: Fwd: race in pg_ctl start -w  (Heikki Linnakangas <hlinnakangas@vmware.com>)
List pgsql-bugs
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.

>> It also flagged a very similar issue (looks like the code was copied &
>> pasted) in initdb.c.  I haven't looked into whether that one is as
>> likely to be subject to a race as the pg_ctl one, but it could be
>> problematic as well.

> I don't think it's a problem for initdb, because the files that it reads
> should not change on the fly. Nevertheless, I guess we might as well add
> a check there.

Yeah, I would prefer to keep the code the same in initdb and pg_ctl,
just because somebody is likely to copy one or the other in future.
The fixed-size-buffer solution does not work for initdb.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Fwd: race in pg_ctl start -w
Next
From: Heikki Linnakangas
Date:
Subject: Re: Fwd: race in pg_ctl start -w