mvniekerk / tokio-cron-scheduler

Schedule tasks on Tokio using cron-like annotation
Apache License 2.0
453 stars 54 forks source link

Getting a RecvError() no matter what I do #57

Open kaspar-p opened 8 months ago

kaspar-p commented 8 months ago

I use this library to run a twitter bot, but I must have changed something, and lately every time the cron job actually starts, it stops immediately with a generic error:

2023-11-14T01:00:00.196354Z ERROR tokio_cron_scheduler::job::creator: /home/pi/.cargo/registry/src/index.crates.io-1cd66030c949c28d/tokio-cron-scheduler-0.9.4/src/job/creator.rs: Error running job a67d2389-3be4-4ca8-8b70-8afd7a202170 RecvError(())

and I'm not sure how to debug. I've put the contents of the job into a cron_tweet() fn, and doing something like:

let hour_offset = 1;
scheduler
    .add(
        // 6pm MST is midnight UTC
        Job::new_async(format!("0 0 {} * * *", hour_offset).as_str(), |_, __| {
            Box::pin(async move {
                cron_tweet().await;
            })
        })
        .unwrap(),
    )
    .await
    .unwrap();

has the error, but just:

cron_tweet().await;

works fine.

The start of my cron_tweet() function is:

async fn cron_tweet() -> () {
    info!("Starting cron...");
    let config: Config = get_config().expect("Getting config failed!");
    let dao = match ant_data_farm::connect_config(config.database).await {
        Err(e) => {
            error!("Failed to initialize database: {}", e);
            error!("Ending CRON early!");
            return;
        }
        Ok(dao) => dao,
    };

  ...

where the dao is a database connection. And I actually see the Starting cron... logs:

2023-11-14T00:55:45.953573Z  INFO ant_who_tweets: projects/ant-who-tweets/src/main.rs: Saw 255 seconds until next job, sleeping for 255 seconds!
2023-11-14T01:00:00.148506Z  INFO ant_who_tweets: projects/ant-who-tweets/src/main.rs: Starting cron...
2023-11-14T01:00:00.196354Z ERROR tokio_cron_scheduler::job::creator: /home/pi/.cargo/registry/src/index.crates.io-1cd66030c949c28d/tokio-cron-scheduler-0.9.4/src/job/creator.rs: Error running job a67d2389-3be4-4ca8-8b70-8afd7a202170 RecvError(())

but then immediately the error. The manual way (no scheduler, just calling cron_tweet().await directly, has all the right logging).

What could RecvError() come from? Why does this happen? It doesn't seem like a bad connection to the DB, or my error! logs would appear, but they aren't...

RoloEdits commented 6 months ago

version 0.9.4 tokio version 1.35.1

Just had this happen as well. Been running fine for a week then suddenly today I get this in my logs. I have error reporting for my own things and had nothing show up there.

its being reported here, line 96: https://github.com/mvniekerk/tokio-cron-scheduler/blob/da2e31087603661e6b4a7679cb4cde72e0ae130e/src/job/creator.rs#L94-L104

From what I can gather, tokio has three errors with this name: image

seems to have something to do with channels?

kaspar-p commented 6 months ago

Yep, I think there must be some kind of race condition within the library. You can see in my Git history link that very minor things change, and this error no longer affects me today.

Really, I added some logging, and things fixed themselves.