diff --git a/src/net/tcp_client.cpp b/src/net/tcp_client.cpp
index ae237d22d871469dd241a2062ff98c1278242be0..7103ed134d6caf48dbd7ac6f69b8b9bb6e88ec13 100644
--- a/src/net/tcp_client.cpp
+++ b/src/net/tcp_client.cpp
@@ -160,11 +160,11 @@ tcp_client::tcp_client(
 {}
 
 tcp_client::~tcp_client() {
-    if (destructor_cb != nullptr) {
+    io.stop();
+
+    if (destructor_cb) {
         destructor_cb(exit_status_t::NO_ERROR);
     }
-
-    io.stop();
 }
 
 void tcp_client::write_data(const std::string &data) {