Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix memory leak in Mojo::Server::Prefork
  • Loading branch information
kraih committed Jan 25, 2015
1 parent 3490887 commit da28997
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@

5.75 2015-01-26
- Fixed race condition in Mojo::Server::Prefork.
- Fixed race condition and memory leak in Mojo::Server::Prefork.

5.74 2015-01-25
- Improved parser errors to be more consistent with connection errors in
Expand Down
25 changes: 11 additions & 14 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -174,31 +174,28 @@ sub _spawn {
$self->setuidgid->cleanup(0);

# Accept mutex
weaken $self;
my $loop = $self->ioloop->lock(
sub {

# Blocking ("ualarm" can't be imported on Windows)
my $lock;
if ($_[0]) {
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
my $old = Time::HiRes::ualarm $self->lock_timeout * 1000000;
$lock = flock $handle, LOCK_EX;
Time::HiRes::ualarm $old;
1;
} or $lock = $@ eq "alarm\n" ? 0 : die $@;
}

# Non-blocking
else { $lock = flock $handle, LOCK_EX | LOCK_NB }
return flock $handle, LOCK_EX | LOCK_NB unless shift;

# Blocking ("ualarm" can't be imported on Windows)
my $lock;
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
my $old = Time::HiRes::ualarm $self->lock_timeout * 1000000;
$lock = flock $handle, LOCK_EX;
Time::HiRes::ualarm $old;
1;
} or $lock = $@ eq "alarm\n" ? 0 : die $@;
return $lock;
}
);
$loop->unlock(sub { flock $handle, LOCK_UN });

# Heartbeat messages
weaken $self;
$loop->recurring(
$self->heartbeat_interval => sub {
my $graceful = shift->max_connections ? 0 : 1;
Expand Down

0 comments on commit da28997

Please sign in to comment.