Git Product home page Git Product logo

Comments (2)

mstyura avatar mstyura commented on June 6, 2024

Hi there! I'm encountering the same problem. As an additional detail I could add that the same crash happen when ctx.notify_later is used. It seems like both ctx.notify_later and ctx.run_internval crashed due to access to tokio::runtime::Handle::current().
Crash is also happen when directly accessing current tokio handle:

use actix::prelude::*;

struct MyActor;

impl Actor for MyActor {
    type Context = Context<Self>;
    
    fn started(&mut self, ctx: &mut Self::Context) {
        tokio::runtime::Handle::current(); // will be paniced
    }
}

fn main() {
    let system = actix::System::new();
    system.block_on(async {
        MyActor.start();
        // Next line fixes panic when uncommented: 
        // tokio::task::yield_now().await;
    });
}

from actix.

thalesfragoso avatar thalesfragoso commented on June 6, 2024

I believe this is caused by the Drop implementation of ContextFut:

impl<A, C> Drop for ContextFut<A, C>
where
C: AsyncContextParts<A> + Unpin,
A: Actor<Context = C>,
{
fn drop(&mut self) {
if self.alive() {
self.ctx.parts().stop();
let waker = futures_task::noop_waker();
let mut cx = std::task::Context::from_waker(&waker);
let _ = Pin::new(self).poll(&mut cx);
}
}
}

The poll will call your started function if ContextFut didn't get the change to be polled before. The thing is, tokio drops its spawned futures after shutting down the runtime, run_interval will try to create a Sleep instance from tokio and then panic.

The Drop implementation is arguably wrong, the poll can run arbitrary code provided by the user (through started, stopping and stopped), and it's understandable that the user will assume that a tokio runtime exists in at least some of these methods.

from actix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.