From 85b610408090f8a92e38bcfbfba9917110e2dd99 Mon Sep 17 00:00:00 2001 From: PobreGato <315121269+pobregat0@users.noreply.github.com> Date: Wed, 19 Aug 2026 19:12:20 +0300 Subject: [PATCH] stop runnable destination in its own thread --- libi2pd/Destination.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index 2dee646c..74a97f58 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "Crypto.h" #include "ECIESX25519AEADRatchetSession.h" @@ -1680,7 +1681,20 @@ namespace client { if (IsRunning ()) { - ClientDestination::Stop (); + // the destination's own thread may still be handling packets of this + // very destination, so tear it down there rather than under the caller + if (GetIOService ().get_executor ().running_in_this_thread ()) + ClientDestination::Stop (); + else + { + std::promise done; + boost::asio::post (GetIOService (), [this, &done]() + { + ClientDestination::Stop (); + done.set_value (); + }); + done.get_future ().wait (); + } StopIOService (); } }