Skip Menu |

This queue is for tickets about the MediaWiki-API CPAN distribution.

Report information
The Basics
Id: 101867
Status: resolved
Priority: 0/
Queue: MediaWiki-API

People
Owner: Nobody in particular
Requestors: derbeth [...] interia.pl
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.41



Subject: Lag retries erroneously reported as 1
Date: Mon, 02 Feb 2015 07:46:52 +0100
To: bug-MediaWiki-API [...] rt.cpan.org
From: Derbeth <derbeth [...] interia.pl>
In "sub api" you will always print "1" as the number of attempts, no matter what the configuration is: if ($maxlagretries == 0) { return $self->_error(ERR_API,"Server has reported lag above the configure max_lag value of " . $self->{config}->{max_lag} . " value after " .($maxlagretries+1)." attempt(s). Last reported lag was - ". $ref->{'error'}->{'info'}) } Naturally, this code gets executed only if $maxlagretries is zero, so you will print 1 as the number of attempts. You loose the original value of this configuration parameter, because you modify the variable in each loop execution. You should use an another variable for counting attempts number instead of decreasing $maxlagretries and never modify $maxlagretries.
Apologies for the delay - it;s been ages since I looked at this code - not sure what I was doing in this part of the code, but I think it should be --- a/lib/MediaWiki/API.pm +++ b/lib/MediaWiki/API.pm @@ -428,7 +428,7 @@ sub api { $ref->{'error'}->{'info'} =~ /: (\d+) seconds lagged/; my $lag = $1; if ($maxlagretries == 0) { - return $self->_error(ERR_API,"Server has reported lag above the configure max_lag value of " . $self->{config}->{max_lag} . " value after " .($maxlagretries+1)." attempt(s). Last reported lag was - ". $ref->{'error'}->{'info'}) + return $self->_error(ERR_API,"Server has reported lag above the configure max_lag value of " . $self->{config}->{max_lag} . " value after " . ($self->{config}->{max_lag_retries}+1) . " attempt(s). Last reported lag was - ". $ref->{'error'}->{'info'}) } else { sleep $self->{config}->{max_lag_delay}; $maxlagretries-- if $maxlagretries > 0; I'll do some testing and update
This seems more sensible actually. --- a/lib/MediaWiki/API.pm +++ b/lib/MediaWiki/API.pm @@ -343,7 +343,7 @@ sub api { unless $self->{config}->{api_url}; my $retries = $self->{config}->{retries}; - my $maxlagretries = $self->{config}->{max_lag_retries}; + my $maxlagretries = 1; $self->_encode_hashref_utf8($query, $options->{skip_encoding}); $query->{maxlag} = $self->{config}->{max_lag} if defined $self->{config}->{max_lag}; @@ -427,11 +427,11 @@ sub api { if (ref($ref) eq 'HASH' && exists $ref->{error} && $ref->{error}->{code} eq 'maxlag' ) { $ref->{'error'}->{'info'} =~ /: (\d+) seconds lagged/; my $lag = $1; - if ($maxlagretries == 0) { - return $self->_error(ERR_API,"Server has reported lag above the configure max_lag value of " . $self->{config}->{max_lag} . " value after " .($maxlagretries+1)." attempt(s). Last reported lag was - ". $ref->{'error'}->{'info'}) + if ($maxlagretries == $self->{config}->{max_lag_retries}) { + return $self->_error(ERR_API,"Server has reported lag above the configured max_lag value of " . $self->{config}->{max_lag} . " value after " . $self->{config}->{max_lag_retries} . " attempt(s). Last reported lag was - ". $ref->{'error'}->{'info'}) } else { sleep $self->{config}->{max_lag_delay}; - $maxlagretries-- if $maxlagretries > 0; + $maxlagretries++ if $maxlagretries < $self->{config}->{max_lag_retries}; # redo the request next; }
should be fixed as of MediaWiki::API 0.41 which will be available shortly. Sorry again for the delay - please let me know if it solves it for you.