Skip to content

Commit

Permalink
added lock_timeout parameter to Hypnotoad
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 1, 2012
1 parent 463c2aa commit 83b3b78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -5,6 +5,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Added EXPERIMENTAL drain event to Mojo::Transaction::WebSocket.
- Added EXPERIMENTAL support for RSV1-3 flags to
Mojo::Transaction::WebSocket.
- Added lock_timeout parameter to Hypnotoad.
- Added x_forwarded_host, x_forwarded_https and x_requested_with
methods to Mojo::Headers.
- Removed experimental status from JSON Pointer support.
Expand Down
13 changes: 11 additions & 2 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -12,6 +12,7 @@ use List::Util 'shuffle';
use Mojo::Server::Daemon;
use POSIX qw/setsid WNOHANG/;
use Scalar::Util 'weaken';
use Time::HiRes 'ualarm';

# Preload
use Mojo::UserAgent;
Expand Down Expand Up @@ -150,6 +151,7 @@ sub _config {
||= File::Spec->catfile($ENV{MOJO_TMPDIR} || File::Spec->tmpdir,
'hypnotoad.lock');
$c->{lock_file} .= ".$$";
$c->{lock_timeout} ||= '0.5';
$c->{pid_file}
||= File::Spec->catfile(dirname($ENV{HYPNOTOAD_APP}), 'hypnotoad.pid');
$c->{upgrade_timeout} ||= 60;
Expand Down Expand Up @@ -356,9 +358,9 @@ sub _spawn {
if ($_[1]) {
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
my $old = alarm 1;
my $old = ualarm $c->{lock_timeout} * 1000000;
$l = flock $lock, LOCK_EX;
alarm $old;
ualarm $old;
};
if ($@) {
die $@ unless $@ eq "alarm\n";
Expand Down Expand Up @@ -585,6 +587,13 @@ also L<Mojo::Server::Daemon/"listen"> for more examples.
Full path to accept mutex lock file, defaults to a random temporary file.
=head2 C<lock_timeout>
lock_timeout => 1
Maximum amount of time in seconds a worker may block when waiting for the
accept mutex, defaults to C<0.5>.
=head2 C<pid_file>
pid_file => '/var/run/hypnotoad.pid'
Expand Down

0 comments on commit 83b3b78

Please sign in to comment.