Skip to content

Commit

Permalink
[RSDK-8578] Revise locking for periodic app client tasks (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
acmorrow authored Aug 19, 2024
1 parent aca1e72 commit 3f5181e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions micro-rdk/src/common/conn/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,25 +412,23 @@ where
loop {
// Wait for the period to expire, then inspect the state of the `AppClient`
// under the read lock. If there is currently an `AppClient` in play, let
// the task use it to conduct it's business. If the task returns a new wait
// the task use a clone to conduct it's business. If the task returns a new wait
// duration, update `duration`. Otherwise, just sleep again and hope that an
// `AppClient` will be available on the next wakeup.
let _ = async_io::Timer::after(duration).await;
let urguard = app_client.upgradable_read().await;
for app_client in urguard.as_ref().iter() {
let app_client = app_client.read().await.clone();
if let Some(app_client) = app_client.as_ref() {
match task.invoke(app_client).await {
Ok(None) => continue,
Ok(Some(next_duration)) => {
duration = next_duration;
}
Err(e) => {
log::error!(
"Periodic task {} failed with error {:?} - dropping app client",
"Periodic task {} failed with error {:?}",
task.name(),
e
);
let _ = AsyncRwLockUpgradableReadGuard::upgrade(urguard).await.take();
break;
}
}
}
Expand Down

0 comments on commit 3f5181e

Please sign in to comment.