Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TokioRuntimeContext in order to abort all spawned tasks #15

Open
5 tasks
ljoss17 opened this issue Apr 17, 2023 · 0 comments
Open
5 tasks

Refactor TokioRuntimeContext in order to abort all spawned tasks #15

ljoss17 opened this issue Apr 17, 2023 · 0 comments

Comments

@ljoss17
Copy link
Contributor

ljoss17 commented Apr 17, 2023

Proposal

The runtime implementation for relayer-next should be updated in order to abort all spawned tasks.

The implementation of TokioRuntimeContext in the relayer-next spawns a new task does not have any method to abort all spawned tasks, https://github.com/informalsystems/hermes/blob/soares/relayer-next/crates/relayer-runtime/src/tokio/context.rs#L24.

One of the use cases for this feature is when running the integration tests with the relayer-next. The current solution only aborts the JoinHandle<()> of the auto_relay() task spawned, https://github.com/informalsystems/hermes/pull/3234/files#diff-50ab12b7fc99fc8b4406c1de2f36eae74380960d5049fe0ec3df3c92c1495f32R421.
Being able to cleanly abort all tasks from the context instead would be better.

One solution could be to keep track of all JoinHandle<()> spawned, https://github.com/informalsystems/hermes/blob/soares/relayer-next/crates/relayer-runtime/src/tokio/context.rs#L95, and have a method abort them and wait for all the tasks to be finished.
A few issues need to be considered for the refactoring:

  • If a Vec<Arc<JoinHandle<()>>> is used, note that Arc<JoinHandle<()>> is not aFuture, so it would need to be changed in order to use futures::future::join_all.
  • The traits OfaFullRuntime, Spawner will need to be refactored as they currently return Box<dyn TaskHandle> and JoinHandle<()> does not implement Copy or Clone. Creating the TokioTaskHandle, adding an Arc to the vector and returning the TokioTaskHandle is not possible due to a borrow error:
    • let tokio_handle = TokioTaskHandle(join_handle); // Moved join_handle
      let arc_handle = Arc::new(tokio_handle);
      handles.push(Arc::clone(&arc_handle));
      Box::new(tokio_handle)                          // Error caused by previous move
      
  • The method spawn() of OfaFullRuntime does not take a mutable reference to self so it would not be possible to simply add a Vec<Arc<JoinHandle<()>>> field to TokioRuntimeContext.

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate milestone (priority) applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@soareschen soareschen transferred this issue from informalsystems/hermes Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🩹 Triage
Development

No branches or pull requests

1 participant