You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
I faced a race condition using
func throttle()
: it is possible to reachawait actor.run(operation)
multiple times in less time than the specifiedduration
parameter.Nothing prevents
throttle()
to be called simultaneously from different threads.Throttler
being anactor
, this is safe but the race condition is still here:let lastDate = lastAttemptDate[identifier]
can be set from 2 (or more) different threads beforeself.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.
The text was updated successfully, but these errors were encountered: