Subject: | Daemon fails to clean up PID file on Windows |
The following code breaks when trying to start the daemon after a crash.
On Windows, an open file creates a file lock.
Because Mojo never closes the PID file handle, the unlink will fail.
You need to make sure you close your filehandles when you are finished
with them.
sub prepare_pid_file {
my $self = shift;
return unless my $file = $self->pid_file;
# PID file
my $fh;
if (-e $file) {
$fh = IO::File->new("< $file")
or croak qq/Can't open PID file "$file": $!/;
my $pid = <$fh>;
warn "Server already running with PID $pid.\n" if kill 0, $pid;
warn qq/Can't unlink PID file "$file".\n/
unless -w $file && unlink $file;
}