Bug 63140 - pid file may get corrupted and prevent httpd from starting
Summary: pid file may get corrupted and prevent httpd from starting
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Core (show other bugs)
Version: 2.5-HEAD
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2019-02-04 10:59 UTC by Nicolas Carrier
Modified: 2019-05-22 14:58 UTC (History)
1 user (show)



Attachments
Avoids pid file creation race condition by using a temporary file. (2.75 KB, patch)
2019-02-04 11:00 UTC, Nicolas Carrier
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Carrier 2019-02-04 10:59:23 UTC
If a power outage occurs at the wrong moment, subsequent attempts to start httpd may fail with the following error:
```
Error retrieving pid file ...
Remove it before continuing if it is corrupted.
```

The way pid files are created in apache is racy. The file is created, then it's content is written to it. If a power outage happens between the two steps, the pid file may stay empty.

A temporary file should be created instead and renamed after it has been written to and flushed.
Comment 1 Nicolas Carrier 2019-02-04 11:00:58 UTC
Created attachment 36417 [details]
Avoids pid file creation race condition by using a temporary file.

The original pattern for creating the pid file was:
open_create(pid_file)
write(pid_file, pid)
close(pid_file)

But if a power outage occurs between open_create and write, the file will
be empty and httpd will refuse to start afterwards unless the corrupt pid
file is removed.

This patch uses the pattern:
open_create(temp_pid_file)
write(temp_pid_file)
close(temp_pid_file)
rename(temp_pid_file, pid_file)
which is guaranteed to be atomic, provided that temp_pid_file and pid_file
are located in the same file system, which this patch does by creating
a temporary file name with the pattern:
    pid_file_name + random_suffix
Comment 2 Nicolas Carrier 2019-05-22 14:58:57 UTC
There has been no progress with this issue for more than 3 month.

Is this issue invalid somehow?
Is the patch not acceptable?