Skip to content

No timer callback after periodic timer cancellation #3013

@brain5lug

Description

@brain5lug
#include <seastar/core/app-template.hh>
#include <seastar/core/timer.hh>
#include <seastar/core/reactor.hh>
#include <seastar/core/print.hh>
#include <seastar/core/thread.hh>
#include <seastar/core/sleep.hh>
#include <chrono>
#include <iostream>

using namespace seastar;
using namespace std::chrono_literals;

struct timer_hang_test {
    timer<steady_clock_type> t1;
    timer<steady_clock_type> t2;
    promise<> pr1;
    promise<> pr2;

    future<> run() {
        t1.set_callback([this](){
            std::cerr << "has t1 callback"<< std::endl;
            if (t1.cancel()) {
                std::cerr << "t1 has been cancelled"<< std::endl;
            }
            pr1.set_value();
        });
        t2.set_callback([this](){
            std::cerr << "no t2 callback"<< std::endl;
            pr2.set_value();
        });

        (void)pr1.get_future().then([this]{
            t2.arm(2ms);
            std::cerr << "t2 has been armed"<< std::endl;
        });

        t1.arm_periodic(1ms);

        // some work here
        std::this_thread::sleep_for(1ms);
        std::cerr << "some work is done"<< std::endl;

        // this future never resolves
        return pr2.get_future();
    }
};

int main(int ac, char** av) {
    app_template app;
    timer_hang_test t1;
    return app.run_deprecated(ac, av, [&t1] {
        fmt::print("=== Start Timer hang test\n");
        return t1.run().then([] {
            fmt::print("Done\n");
            engine().exit(0);
        });
    });
}

The test hangs untill Ctrl+C is pressed. The text fails 100%. Full test output:

WARN  2025-10-02 12:29:11,090 seastar - Your system does not have enough AIO capacity for optimal network performance; reducing `max-networking-io-control-blocks'.
WARN  2025-10-02 12:29:11,090 seastar - Resultant AIO control block usage:
WARN  2025-10-02 12:29:11,090 seastar - 
WARN  2025-10-02 12:29:11,090 seastar - purpose  per cpu  all 8 cpus
WARN  2025-10-02 12:29:11,090 seastar - -------  -------  ----------
WARN  2025-10-02 12:29:11,090 seastar - reserve                    0
WARN  2025-10-02 12:29:11,090 seastar - storage     1024        8192
WARN  2025-10-02 12:29:11,090 seastar - preempt        2          16
WARN  2025-10-02 12:29:11,090 seastar - network     7166       57328
WARN  2025-10-02 12:29:11,090 seastar - -------  -------  ----------
WARN  2025-10-02 12:29:11,090 seastar - total       8192       65536
WARN  2025-10-02 12:29:11,090 seastar - 
WARN  2025-10-02 12:29:11,090 seastar - For optimal network performance, set /proc/sys/fs/aio-max-nr to at least 88208.
INFO  2025-10-02 12:29:11,091 seastar - Reactor backend: linux-aio
INFO  2025-10-02 12:29:11,092 seastar - Perf-based stall detector creation failed (EACCESS), try setting /proc/sys/kernel/perf_event_paranoid to 1 or less to enable kernel backtraces: falling back to posix timer.
INFO  2025-10-02 12:29:11,102 [shard 0:main] seastar - IO queue was unable to find a suitable maximum request length, the search was cut-off early at: 16MB
INFO  2025-10-02 12:29:11,102 [shard 0:main] seastar - IO queue was unable to find a suitable maximum request length, the search was cut-off early at: 16MB
=== Start Timer hang test
some work is done
has t1 callback
t1 has been cancelled
t2 has been armed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions