Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Throttler token time calculation #7160

Merged
merged 3 commits into from
Jan 27, 2023

Conversation

rumpfc
Copy link
Contributor

@rumpfc rumpfc commented Jan 21, 2023

Description
In one of my applications where I use Throttler I detected the getTokenTime() is already at the minimum of 1 seconds even if the token refresh rate is far from reached:

Example: 1 capacity, 3600 seconds -> After 10 minutes I expected 50 minutes to be left, but I was already at "1 second". Waiting another minute and executing the check, I was still at "1 second left".

This made me clear that the calculation for Throttler::getTokenTime() is still off, but the token value is calculated correctly after all, return false if $token < 1. This PR should fix that.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 22, 2023
Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

Good sleuthing! Very cool test. Thanks for the PR!

@MGatner MGatner merged commit 629eae1 into codeigniter4:develop Jan 27, 2023
@rumpfc rumpfc deleted the fix-throttler branch January 27, 2023 12:06
@kenjis kenjis changed the title Fix: Throttler token time calculation fix: Throttler token time calculation Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants