From fef1fe7dcd44d17e5c8e3c0fe3c2698a8aac038e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 1 Feb 2014 02:07:50 +0000 Subject: [PATCH] connection/poolable: defer expiry of timed out connections The timeout check may run on a socket before epoll_wait/kevent has a chance to run, giving the application no chance for any readiness callbacks to fire. This prevents timeouts in the monitor if the database is slow during synchronous UPDATE device calls (or there are just thousands of active connections). --- lib/MogileFS/Connection/Poolable.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/MogileFS/Connection/Poolable.pm b/lib/MogileFS/Connection/Poolable.pm index c9ee84a..86b99d4 100644 --- a/lib/MogileFS/Connection/Poolable.pm +++ b/lib/MogileFS/Connection/Poolable.pm @@ -105,6 +105,7 @@ sub set_timeout { my ($self, $timeout_key) = @_; my $mfs_pool = $self->{mfs_pool}; + $self->SetPostLoopCallback(undef); if ($timeout_key) { my $timeout; @@ -144,7 +145,7 @@ sub expired { if ($now >= $expire) { my $expire_cb = delete $self->{mfs_expire_cb}; if ($expire_cb && $self->sock) { - $expire_cb->($now); + $self->SetPostLoopCallback(sub { $expire_cb->($now); 1 }); } return 1; } -- 2.11.4.GIT