[squid-dev] [PATCH] Create PID file ASAP

Amos Jeffries squid3 at treenet.co.nz
Mon May 15 11:43:51 UTC 2017


On 15/05/17 20:34, Eduard Bagdasaryan wrote:
> Hello,
>
>
> With this fix applied, PID file is created right after configuration
> finalization, before the allocation for any shared memory segments.
>
> Late PID file creation allowed N+1 concurrent Squid instances to create
> the same set of shared segments (overwriting each other segments),
> resulting in extremely confusing havoc because the N instances would
> later lose the race for the PID file (or some other critical resource)
> creation and remove the segments. If that removal happened before a kid
> of the single surviving instance started, that kid would fail to start
> with open() errors in Segment.cc because the shared segment it tries to
> open would be gone. Otherwise, that kid would fail to _restart_ after
> any unrelated failures (possibly many days after the conflict), with
> same errors, for the same reason.
>
> Shared state corruption was also possible if different kids (of the
> winning instance) opened (and started using) segments created (and
> initialized) by different instances.
>
> Situations with N+1 concurrent Squid instances are not uncommon because
> many Squid service management scripts (or manual admin commands!)
> * do not check whether another Squid is already running and/or
> * incorrectly assume that "squid -z" does not daemonize.
>
> This change finally makes starting N+1 Squid instances safe (AFAIK).
>
> Also made daemonized and non-daemonized Squid create the PID file at the
> same startup stage, reducing inconsistencies between the two modes.
>
> This patch should be applied after applying PID file creation 
> atomicity fix:
> http://lists.squid-cache.org/pipermail/squid-dev/2017-May/008584.html
>

Looks reasonable to me, though I have not fully traced the differences 
in SUID scope most of them seems to be increases to what runs as 
low-privileged user.

Amos



More information about the squid-dev mailing list