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

Race condition in throttle() #4

Open
MartinMoizard opened this issue Jan 29, 2024 · 0 comments
Open

Race condition in throttle() #4

MartinMoizard opened this issue Jan 29, 2024 · 0 comments

Comments

@MartinMoizard
Copy link

I faced a race condition using func throttle(): it is possible to reach await actor.run(operation) multiple times in less time than the specified duration parameter.

Nothing prevents throttle() to be called simultaneously from different threads. Throttler being an actor, this is safe but the race condition is still here: let lastDate = lastAttemptDate[identifier] can be set from 2 (or more) different threads before self.lastAttemptDate[identifier] = Date() is reached.

When this happens, the operation is called multiple times in a row, breaking the throttle contract.

I'll try to suggest a fix later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant