Fixing the race condition in shlock.c

Berend Reitsma breitsma+inn at gmail.com
Fri Oct 17 12:36:51 UTC 2008


Hi Julien,

I have atached my current version of shlock.c. I don't know if the
mailing list will strip attachements...

> I do not manage to reproduce the race condition with STABLE INN 2.4.5
> shlock program.  I do not see "shlock race condition" in the output
> of your script...

I downloaded the latest source from isc.org yesterday and the source
of shlock.c did not have a fix for the race condition in that version
either.

> Should the race condition happen at least once during its execution?

Not necessarily. It is pretty difficult to trigger on a single cpu
(single core) system. It all depends on the scheduling of the
processes. On my dual core system I get multiple failures almost every
run. On my old pentium 3 it does run without a failure most of the
time.

The race condition is that there is a timewindow between the discovery
of an invalid lock and the removal of that lockfile. The lockfile that
is removed might be another file than the one you checked. This can
happen because another shlock might have done the same check but did
not yet remove the lockfile because of OS scheduling. You will happily
remove the file, create a new lockfile and return success. If the OS
than schedules the other shlock again, it will continue to remove the
lockfile, create a new lockfile and return success too. At this point
you have two processes running within the locked part...

Regards,
  Berend.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shlock.c
Type: text/x-csrc
Size: 6737 bytes
Desc: not available
URL: <https://lists.isc.org/pipermail/inn-workers/attachments/20081017/a9b7e2e5/attachment.bin>


More information about the inn-workers mailing list