From 4cd3c06881da36304d0a3b9a881bc46f148daff5 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Mon, 5 Sep 2011 16:48:31 +0200 Subject: [PATCH] In MetaCPAN::Web::Model::API::request, retry once if we get a connection timeout --- lib/MetaCPAN/Web/Model/API.pm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/MetaCPAN/Web/Model/API.pm b/lib/MetaCPAN/Web/Model/API.pm index aff5cbbf08..7a674e603e 100644 --- a/lib/MetaCPAN/Web/Model/API.pm +++ b/lib/MetaCPAN/Web/Model/API.pm @@ -39,7 +39,7 @@ sub model { } sub request { - my ( $self, $orig_path, $search, $params ) = @_; + my ( $self, $orig_path, $search, $params, $timed ) = @_; my ( $token, $method ) = @$params{qw(token method)}; my $path = $orig_path; $path .= "?access_token=$token" if ($token); @@ -52,12 +52,15 @@ sub request { persistent => 1, sub { my ( $data, $headers ) = @_; - if ( $headers->{Status} == 596 - && $headers->{Reason} eq 'Broken pipe' ) + if ($headers->{Status} == 596 + and ( $headers->{Reason} eq 'Broken pipe' + or $headers->{Reason} =~ /timed out/ and not $timed++ ) + ) { - my $cv = $self->request( $orig_path, $search, $params ); + my $cv = $self->request( $orig_path, $search, $params, $timed ); return $cv->cb( sub { $req->send( $cv->recv ) } ); } + my $content_type = $headers->{'content-type'} || ''; if ( $content_type =~ /^application\/json/ ) {