Skip to content

Commit

Permalink
ignore errors resulting from cancellation of the task
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Jun 27, 2024
1 parent 5fb9717 commit 3748bee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
11 changes: 6 additions & 5 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,12 @@ impl FfiStreamCloser {
let handle = handle.take();
if let Some(h) = handle {
h.abort();
h.await.map_err(|_| GenericError::Generic {
err: "subscription event loop join error".into(),
})??;
let join_result = h.await;
if matches!(join_result, Err(ref e) if !e.is_cancelled()) {
return Err(GenericError::Generic {
err: format!("subscription event loop join error {}", join_result.unwrap_err()),
})
}
} else {
log::warn!("subscription already closed");
}
Expand Down Expand Up @@ -1139,9 +1142,7 @@ mod tests {
log::info!("Received: {}", String::from_utf8_lossy(&message.content));
messages.push(message);
let _ = self.num_messages.fetch_add(1, Ordering::SeqCst);
log::debug!("NOTIFYING");
self.notify.notify_one();
log::debug!("NOTIFIED");

}
}
Expand Down
9 changes: 6 additions & 3 deletions bindings_ffi/src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,12 @@ impl FfiV2Subscription {
let handle = handle.take();
if let Some(h) = handle {
h.abort();
h.await.map_err(|_| GenericError::Generic {
err: "subscription event loop join error".into(),
})?;
let join_result = h.await;
if matches!(join_result, Err(ref e) if !e.is_cancelled()) {
return Err(GenericError::Generic {
err: format!("subscription event loop join error {}", join_result.unwrap_err()),
})
}
}
Ok(())
}
Expand Down
9 changes: 5 additions & 4 deletions xmtp_mls/src/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,11 @@ mod tests {
let messages = messages.lock().unwrap();
assert_eq!(messages.len(), 5);
}

handle.abort();
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
assert!(handle.is_finished());

let a = handle.abort_handle();
a.abort();
handle.await.unwrap();

Check warning on line 493 in xmtp_mls/src/subscriptions.rs

View workflow job for this annotation

GitHub Actions / Test

unused `std::result::Result` that must be used

Check warning on line 493 in xmtp_mls/src/subscriptions.rs

View workflow job for this annotation

GitHub Actions / workspace

unused `std::result::Result` that must be used

warning: unused `std::result::Result` that must be used --> xmtp_mls/src/subscriptions.rs:493:9 | 493 | handle.await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 493 | let _ = handle.await.unwrap(); | +++++++
assert!(a.is_finished());

alix_group
.send_message("first".as_bytes(), &alix)
Expand Down

0 comments on commit 3748bee

Please sign in to comment.