Skip to content

Commit d43d84f

Browse files
authored
Merge pull request #227 from UiPath/fix-wait-hang
Fix hang in wait_all_exit
2 parents 4aac6ff + 092d768 commit d43d84f

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/asynchronous/shutdown.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,25 @@ impl Notifier {
144144
/// Wait for all [`Waiter`]s to drop.
145145
pub async fn wait_all_exit(&self) -> Result<(), Elapsed> {
146146
//debug_assert!(self.shared.is_shutdown());
147-
if self.waiters() == 0 {
148-
return Ok(());
149-
}
150-
let wait = self.wait();
151-
if self.waiters() == 0 {
152-
return Ok(());
153-
}
154-
wait.await
155-
}
156-
157-
async fn wait(&self) -> Result<(), Elapsed> {
158147
if let Some(tm) = self.wait_time {
159-
timeout(tm, self.shared.notify_exit.notified()).await
148+
timeout(tm, self.wait()).await
160149
} else {
161-
self.shared.notify_exit.notified().await;
150+
self.wait().await;
162151
Ok(())
163152
}
164153
}
154+
155+
async fn wait(&self) {
156+
while self.waiters() > 0 {
157+
let notified = self.shared.notify_exit.notified();
158+
if self.waiters() == 0 {
159+
return;
160+
}
161+
notified.await;
162+
// Some waiters could have been created in the meantime
163+
// by calling `subscribe`, loop again
164+
}
165+
}
165166
}
166167

167168
impl Drop for Notifier {

0 commit comments

Comments
 (0)