Subject: | alive() has a race condition. |
The alive() method calls read(), which obtains a lock and then releases that lock.
Next, alive() calls write(), which obtains a lock and then releases the lock.
However, there is an opportunity for another process to obtain a lock between the time that read() and write() are called. This is a race condition. For example:
1. Process A does a read and sees that the pid file is available.
2. Next, process B also does a read and sees that the pid file is available.
3. Now, Process A does a write and thinks that it has obtained a lock on the pid file.
4. However Process B, having already passed the read test, will over-write Process A's lock.
5. At this point, both processes think they have an exclusive lock.