Page MenuHomePhabricator

Implicit float -> int conversions in WRStatsWriter due to non-integer time step
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Make sure you're using PHP 8.1+
  • Add the following to your LocalSettings.php:
$wgRateLimits['sendemail'] = [ 'user' => [ 1, 1001 ] ];
  • Make sure you have caches enabled (e.g., $wgMainCacheType = CACHE_ACCEL)
  • Go to Special:EmailUser, choose a valid email target and submit

What happens?:
You'll get the following PHP warnings:

Deprecated: Implicit conversion from float 1034.3666666666666 to int loses precision in /var/www/html/w/includes/libs/WRStats/WRStatsWriter.php on line 70

Deprecated: Implicit conversion from float 1034.3666666666666 to int loses precision in /var/www/html/w/includes/libs/WRStats/WRStatsWriter.php on line 71

Deprecated: Implicit conversion from float 1034.3666666666666 to int loses precision in /var/www/html/w/includes/libs/WRStats/WRStatsWriter.php on line 73

What should have happened instead?:
No PHP warnings.

Software version (skip for WMF-hosted wikis like Wikipedia):
MW master as of 2023-05-31.

Other information (browser name/version, screenshots, etc.):
The issue here is that the ratelimit period (1001) is not a multiple of the bucket count defined in WRStatsRateLimiter (30). The time step is computed as $period / $bucketCount, and in this case it's not an integer. The value is then used as an array key, which emits the deprecation warnings in question. Note that this bug exists with any user right, and potentially things other than the ratelimiter using WRStats.

Event Timeline

Krinkle added subscribers: tstarling, Krinkle.

@tstarling Can you take a look for this one?

Change 939784 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/core@master] Round up SequenceSpec::hardExpiry to the nearest integer

https://gerrit.wikimedia.org/r/939784

Change 939784 merged by jenkins-bot:

[mediawiki/core@master] WRStats: Round up SequenceSpec::hardExpiry to the nearest integer

https://gerrit.wikimedia.org/r/939784

Change 940460 had a related patch set uploaded (by Zabe; author: Tim Starling):

[mediawiki/core@REL1_40] WRStats: Round up SequenceSpec::hardExpiry to the nearest integer

https://gerrit.wikimedia.org/r/940460

Change 940461 had a related patch set uploaded (by Zabe; author: Tim Starling):

[mediawiki/core@REL1_39] WRStats: Round up SequenceSpec::hardExpiry to the nearest integer

https://gerrit.wikimedia.org/r/940461

Change 940461 merged by jenkins-bot:

[mediawiki/core@REL1_39] WRStats: Round up SequenceSpec::hardExpiry to the nearest integer

https://gerrit.wikimedia.org/r/940461

Change 940460 merged by jenkins-bot:

[mediawiki/core@REL1_40] WRStats: Round up SequenceSpec::hardExpiry to the nearest integer

https://gerrit.wikimedia.org/r/940460