This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit 3206e809dafd09dfd771aee51bfc1d19ae8893be
Author: Andrew Stitcher <[email protected]>
AuthorDate: Fri May 15 18:53:49 2026 -0400

    PROTON-2834: [C++] Container stop should ignore cancelled timers
    
    Container stop is documented to stop the container after queued qork is
    completed. However if shouldn't wait for any timer work that has already
    been cancelled. So if there are only cancelled timers left it should
    exit immediately.
---
 cpp/src/container_test.cpp          | 16 ++++++++++++++++
 cpp/src/proactor_container_impl.cpp |  9 +++++++++
 2 files changed, 25 insertions(+)

diff --git a/cpp/src/container_test.cpp b/cpp/src/container_test.cpp
index 09dffd5b2..4ac165bc6 100644
--- a/cpp/src/container_test.cpp
+++ b/cpp/src/container_test.cpp
@@ -332,6 +332,21 @@ int test_container_schedule_stop() {
     return 0;
 }
 
+struct cancel_schedule_tester : public proton::messaging_handler {
+    proton::work_handle timeout_handle;
+    void on_container_start(proton::container& c) override {
+        c.cancel(timeout_handle);
+    }
+};
+
+int test_container_cancel_schedule_autostop() {
+    cancel_schedule_tester tester;
+    proton::container c(tester);
+    tester.timeout_handle = c.schedule(proton::duration(10000), [&](){ 
c.stop(); });
+    c.run();
+    return 0;
+}
+
 class link_test_handler : public proton::messaging_handler {//, public 
proton::listen_handler {
   public:
     bool had_receiver;
@@ -706,6 +721,7 @@ int main(int argc, char** argv) {
     RUN_ARGV_TEST(failed, test_container_immediate_stop());
     RUN_ARGV_TEST(failed, test_container_pre_stop());
     RUN_ARGV_TEST(failed, test_container_schedule_stop());
+    RUN_ARGV_TEST(failed, test_container_cancel_schedule_autostop());
     RUN_ARGV_TEST(failed, test_container_links_no_properties());
     RUN_ARGV_TEST(failed, test_container_links_properties());
     RUN_ARGV_TEST(failed, test_container_mt_stop_empty());
diff --git a/cpp/src/proactor_container_impl.cpp 
b/cpp/src/proactor_container_impl.cpp
index 228002e38..6489beaef 100644
--- a/cpp/src/proactor_container_impl.cpp
+++ b/cpp/src/proactor_container_impl.cpp
@@ -473,6 +473,10 @@ work_handle container::impl::schedule(duration delay, work 
f) {
 void container::impl::cancel(work_handle work_handle) {
     GUARD(deferred_lock_);
     is_active_.erase(work_handle);
+    bool active_tasks = is_active_.size() > 0;
+    if (!active_tasks) {
+        pn_proactor_cancel_timeout(proactor_);
+    }
 }
 
 void container::impl::client_connection_options(const connection_options 
&opts) {
@@ -858,6 +862,11 @@ void container::impl::stop(const proton::error_condition& 
err) {
     set_error_condition(err, error_condition);
     pn_proactor_disconnect(proactor_, error_condition);
     pn_condition_free(error_condition);
+    GUARD(deferred_lock_);
+    bool active_tasks = is_active_.size() > 0;
+    if (!active_tasks) {
+        pn_proactor_cancel_timeout(proactor_);
+    }
 }
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to