Skip to content

Commit

Permalink
Fix race condition in error collection; add another warning for dropp…
Browse files Browse the repository at this point in the history
…ed errors
  • Loading branch information
Finomnis committed Oct 13, 2023
1 parent 4baaf7f commit 8836224
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/subsystem/error_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl<ErrType: ErrTypeTraits> ErrorCollector<ErrType> {
match self {
ErrorCollector::Collecting(receiver) => {
let mut errors = vec![];
receiver.close();
while let Ok(e) = receiver.try_recv() {
errors.push(e);
}
Expand All @@ -29,3 +30,14 @@ impl<ErrType: ErrTypeTraits> ErrorCollector<ErrType> {
}
}
}

impl<ErrType: ErrTypeTraits> Drop for ErrorCollector<ErrType> {
fn drop(&mut self) {
if let Self::Collecting(receiver) = self {
receiver.close();
while let Ok(e) = receiver.try_recv() {
tracing::warn!("An error got dropped: {e:?}");
}
}
}
}
1 change: 1 addition & 0 deletions src/toplevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl<ErrType: ErrTypeTraits> Toplevel<ErrType> {
) -> Result<(), GracefulShutdownError<ErrType>> {
let collect_errors = move || {
let mut errors = vec![];
self.errors.close();
while let Ok(e) = self.errors.try_recv() {
errors.push(e);
}
Expand Down

0 comments on commit 8836224

Please sign in to comment.