Skip to content

Commit

Permalink
bpfd: Fix use of tokio::join
Browse files Browse the repository at this point in the history
From the docs, join doesn't spawn. If we want parallelism, we're
supposed to call spawn first. This is necessary so that we can
spawn the image_manager thread before the state reconstruction
occurs.

Signed-off-by: Dave Tucker <[email protected]>
  • Loading branch information
dave-tucker committed Nov 15, 2023
1 parent 2b3d423 commit f5378e0
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions bpfd/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ pub async fn serve(

let allow_unsigned = config.signing.as_ref().map_or(true, |s| s.allow_unsigned);
let (itx, irx) = mpsc::channel(32);

let mut image_manager =
ImageManager::new(BYTECODE_IMAGE_CONTENT_STORE, allow_unsigned, irx).await?;
let image_manager_handle = tokio::spawn(async move {
image_manager.run().await;
});

let mut bpf_manager = BpfManager::new(config, rx, itx);
bpf_manager.rebuild_state().await?;
Expand All @@ -101,19 +105,28 @@ pub async fn serve(
};
if csi_support {
let storage_manager = StorageManager::new(tx);

join!(
let storage_manager_handle = tokio::spawn(storage_manager.run());
let (_, res_image, res_storage, _) = join!(
join_listeners(listeners),
bpf_manager.process_commands(),
image_manager.run(),
storage_manager.run()
image_manager_handle,
storage_manager_handle,
bpf_manager.process_commands()
);
if let Some(e) = res_storage.err() {
return Err(e.into());
}
if let Some(e) = res_image.err() {
return Err(e.into());
}
} else {
join!(
let (_, res_image, _) = join!(
join_listeners(listeners),
bpf_manager.process_commands(),
image_manager.run(),
image_manager_handle,
bpf_manager.process_commands()
);
if let Some(e) = res_image.err() {
return Err(e.into());
}
}

Ok(())
Expand Down

0 comments on commit f5378e0

Please sign in to comment.