Skip to content

Conversation

@Seldaek
Copy link
Member

@Seldaek Seldaek commented Mar 29, 2022

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Refs #44996
License MIT
Doc PR symfony/symfony-docs#...

When reloading an old RateLimiter instance from cache with the new code I did get an exception because windowEndAt was a string and getHitCount does windowEndAt - intervalInSeconds, and string - int fails.

The reason is the new code assigns the id to windowEndAt via:

        $pack = key($data);
        $this->windowEndAt = $data[$pack];

I dumped $this and $data in __unserialize just FYI and you get this:

object(Symfony\Component\RateLimiter\Policy\SlidingWindow)[959]
  private 'id' => null
  private 'hitCount' => int 0
  private 'hitCountForLastWindow' => int 0
  private 'intervalInSeconds' => null
  private 'windowEndAt' => null
array (size=5)
  '�Symfony\Component\RateLimiter\Policy\SlidingWindow�id' => string 'login_per_ip-127.0.0.1' (length=22)
  '�Symfony\Component\RateLimiter\Policy\SlidingWindow�hitCount' => int 2
  '�Symfony\Component\RateLimiter\Policy\SlidingWindow�intervalInSeconds' => int 60
  '�Symfony\Component\RateLimiter\Policy\SlidingWindow�hitCountForLastWindow' => int 0
  '�Symfony\Component\RateLimiter\Policy\SlidingWindow�windowEndAt' => float 1648544909.4762

I only tested the code in real conditions for SlidingWindow, but I do believe/hope the same applies for the other two policies.

$this->tokens = $data[1];
$this->timer = $data[2];
$this->burstSize = $data[3];
$this->stringRate = $data[4];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actualy let's remove this one, remove wakeup and move its logic here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh no! that'd break compat with php < 7.4

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->rate = Rate::fromString($data[4]); then

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah missed that the stringRate prop does not exist :)

@nicolas-grekas
Copy link
Member

Thank you @Seldaek.

@nicolas-grekas nicolas-grekas merged commit 45d0023 into symfony:5.4 Mar 29, 2022
@Seldaek Seldaek deleted the patch-21 branch March 29, 2022 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants