Skip to content

Commit

Permalink
Workaround for browser future not being Send
Browse files Browse the repository at this point in the history
This is incredibly hard to diagnose, because the compiler error is
useless.
  • Loading branch information
einarmo committed Jan 8, 2025
1 parent 937b4e5 commit 7a39591
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
22 changes: 15 additions & 7 deletions lib/tests/integration/browse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,20 +617,28 @@ async fn test_recursive_browser() {
.is_some());
}

// Test that the future returned by `browser.run...` is `Send`
fn assert_send<R: Send>(v: R) -> R {
v
}

#[tokio::test]
// Hit the same node multiple times.
async fn test_recursive_browser_multi_hit() {
let (_tester, _nm, session) = setup().await;

let filter = BrowseFilter::new(BrowseDirection::Forward, ReferenceTypeId::References, true);

let to_browse = vec![filter.new_description_from_node(ObjectId::TypesFolder.into())];
let res = session
.browser()
.max_concurrent_requests(3)
.handler(filter)
.run_into_result(to_browse)
.await
.unwrap();
let res = assert_send(
session
.browser()
.max_concurrent_requests(3)
.handler(filter)
.run_into_result(to_browse),
)
.await
.unwrap();

assert_eq!(4228, res.nodes.len());

Expand Down
7 changes: 6 additions & 1 deletion opcua-client/src/session/retry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::Duration;

use futures::FutureExt;
use opcua_types::StatusCode;

use crate::retry::ExponentialBackoff;
Expand Down Expand Up @@ -138,7 +139,11 @@ impl Session {
) -> Result<T::Out, StatusCode> {
loop {
let next_request = request.clone();
match next_request.send(&self.channel).await {
// Removing `boxed` here causes any futures calling this to be non-send,
// due to a compiler bug. Look into removing this in the future.
// TODO: Check if tests compile without this in future rustc versions, especially
// if https://github.com/rust-lang/rust/issues/100013 is closed.
match next_request.send(&self.channel).boxed().await {
Ok(r) => break Ok(r),
Err(e) => {
if let Some(delay) = policy.get_next_delay(e) {
Expand Down

0 comments on commit 7a39591

Please sign in to comment.