rate-limiter. re-acquire lock after sleep to prevent use-after-free
I thought rust fixed this... Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I3a2fe427cdc19a6317510e8736fe46d56a6a6964
This commit is contained in:
parent
7ee9ee1159
commit
8ed0b6fb12
1 changed files with 5 additions and 3 deletions
|
|
@ -87,13 +87,15 @@ impl RateLimiter {
|
||||||
if wait_time > Duration::ZERO {
|
if wait_time > Duration::ZERO {
|
||||||
drop(inner);
|
drop(inner);
|
||||||
tokio::time::sleep(wait_time).await;
|
tokio::time::sleep(wait_time).await;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut inner = self.inner.lock().await;
|
let mut inner = self.inner.lock().await;
|
||||||
let platform_requests =
|
let platform_requests =
|
||||||
inner.requests.entry(platform.to_string()).or_default();
|
inner.requests.entry(platform.to_string()).or_default();
|
||||||
platform_requests.push(Instant::now());
|
platform_requests.push(Instant::now());
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
platform_requests.push(Instant::now());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue