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

Drop a runtime in futures #1950

Closed
nanne007 opened this issue Dec 12, 2019 · 5 comments
Closed

Drop a runtime in futures #1950

nanne007 opened this issue Dec 12, 2019 · 5 comments

Comments

@nanne007
Copy link

nanne007 commented Dec 12, 2019

Version

tokio v0.2.4

Platform

Darwin Kernel Version 19.0.0

Description

It's not possible to drop a tokio runtime in async context.

for example:

struct A {
    _rt: Runtime,
}

impl A {
    pub async foo(&self) {}
}

struct B {
    a: A,
}

impl B{
   pub async bar(&self) { self.a.foo.await }
}

pub async foobar(b: B) {
    b.bar()
    // here, dropping `a` will fail.  dropping `BlockingPool` needs `enter`, 
    //which is not available in context of futures.
}

Fow now, I have to keep track of every usage on structs who contain Runtime, and make sure they are dropped in non-async context.

@carllerche
Copy link
Member

Dropping a runtime is intended to be a blocking operation.

Can you tell me why you need to hold a runtime from a future? Can you hold a runtime::Handle instead?

@nanne007
Copy link
Author

nanne007 commented Dec 12, 2019

@carllerche

Our code embraces async using actor model.
And different actors may run in a different runtime, which is hold by a supervisor actor.
When stopping the supervisor actor, we also use async to do this,
and then we encountered the problem.

If dropping a runtime is a blocking operation, I think we may need to change the way of handling runtime.

@LucioFranco
Copy link
Member

You shouldn't need multiple runtimes to run an actor system, have you taken a look #1879? Might have some better solutions to this problem.

@nanne007
Copy link
Author

@LucioFranco thanks for the issue!
Will feedback later on this.

@Darksonn
Copy link
Contributor

Fixed by #2646.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants