Skip to content

Indirection/abstraction over tokio::spawn and friends #2979

@matheus23

Description

@matheus23

Iroh's use of tokio is very particular/opinionated.

  • No use of tokio::spawn without wrapping the JoinHandle with AbortOnDropHandle
  • No use of JoinSet::spawn without some loop somewhere calling tasks.join_next().await, if !tasks.is_empty() (to avoid leaking memory from task results accumulating) (EDIT: this might only be necessary if used with else inside tokio::select!, see refactor(iroh, iroh-relay): JoinSet disabling in tokio::select! #3052 )
  • Every spawn must use an .instrument() for tracing.

Furthermore, for iroh in the browser (#2799) we will need to abstract away all tokio::spawn usage because it's not available in the browser! (I've already implemented a JoinSet alternative on top of wasm_bindgen_futures for exactly that reason)

Given that such an indirection would have to be created for the browser work anyways, this might be a good opportunity to introduce an API at that indirection that avoids all of the above footguns (forgetting .instrument(), leaking tasks, leaking memory).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions