Skip to content

Dropping the Client from within an async function panics #148

Open
@milgner

Description

@milgner

Using a pre-existing Tokio Runtime is already part of the README as a potential improvement - so it's probably not a surprise, but I nonetheless wanted to report this problem for completeness:

In our application we're dropping the OPC UA Client from within an async function. But since this will also drop the Tokio Runtime of the associated TCP Transport, it panics with the following error:

thread 'tokio-runtime-worker' panicked at 'Cannot drop a runtime in a context where blocking is not allowed. This happens when a runtime is dropped from within an asynchronous context.',
tokio-1.12.0/src/runtime/blocking/shutdown.rs:51:21

For now this is not a blocker for us because the panic is handled gracefully but it would probably be a good idea to discuss alternatives. I haven't spent any time on concrete ideas but off-the-cuff, I see the following two approaches:

  • refactor all interfaces to async: it would probably be a lot of work (and require the async-trait crate, probably, too) and I'd understand if you'd like to avoid the associated complexity
  • allow library users to provide an async runner: it would basically just need to implement a function pub fn block_on<F: Future>(&self, future: F) -> F::Output just like the Tokio Runtime. This might even make it possible for users to use async_std::task::block_on if they don't want to use Tokio but async-std instead. Could be made backwards-compatible with a default constructor that creates a Tokio Runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions