mvniekerk / tokio-cron-scheduler

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

`Tick send error SendError(true)` after a while #35

Open jukanntenn opened 1 year ago

jukanntenn commented 1 year ago

I have an application using tokio-cron-scheduler. However, after the application starting and running for a while, the cron scheduler no longer work and print Tick send error SendError(true) to the console every 500ms.

I did some investigation on it, here is the source code where produce the error:

loop {
        if let Err(e) = tx.send(true) {
            let shutdown = { *(shutdown.read().await) };
            if shutdown {
                return;
            }
            error!("Tick send error {:?}", e);
        }
        tokio::time::sleep(Duration::from_millis(500)).await;
    }

tokio::sync::broadcast::Sender documentation says

An unsuccessful send would be one where all associated [Receiver] handles have already been dropped.

I have no idea why this occurs. Would you please provide some hints or suggestions for how to debug this error? Since my application is a little complex, so I'm sorry that I can't provide a minimal example to reproduce the issue.

Thanks a lot!

mvniekerk commented 1 year ago

Hi @jukanntenn Yes, an MPSC receiver channel was dropped somewhere causing this. Can be that your job scheduler variable ran out of scope. It is a bit hard to debug without the code though.