Skip to content

Commit 2a2a529

Browse files
authored
Merge pull request #88 from mpretty-cyro/fix/networking-crashes
Fixed a couple of crashes with the new networking release
2 parents 4ddbb27 + 80f0200 commit 2a2a529

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if(CCACHE_PROGRAM)
1717
endif()
1818

1919
project(libsession-util
20-
VERSION 1.6.1
20+
VERSION 1.6.2
2121
DESCRIPTION "Session client utility library"
2222
LANGUAGES ${LANGS})
2323

src/network/routing/onion_request_router.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,9 @@ OnionRequestRouter::OnionRequestRouter(
343343
}
344344

345345
OnionRequestRouter::~OnionRequestRouter() {
346-
std::vector<std::thread> threads_to_join;
347-
348346
// Use 'call_get' to force this to be synchronous
349347
if (_loop)
350-
_loop->call_get([this, &threads_to_join] {
351-
// Harvest upload thread handles *before* _close_connections clears the map
352-
for (auto& [_, upload] : _active_uploads)
353-
if (upload.second.joinable())
354-
threads_to_join.push_back(std::move(upload.second));
355-
356-
_close_connections();
357-
});
358-
359-
// Block until upload threads have finished
360-
for (auto& t : threads_to_join)
361-
if (t.joinable())
362-
t.join();
348+
_loop->call_get([this] { _close_connections(); });
363349

364350
log::debug(cat, "Destroyed.");
365351
}
@@ -662,8 +648,13 @@ void OnionRequestRouter::_pre_build_paths_if_needed() {
662648
}
663649

664650
void OnionRequestRouter::_close_connections() {
651+
std::vector<std::thread> threads_to_join;
652+
665653
// Cancel any uploads and downloads
666654
for (auto& [id, request_and_thread] : _active_uploads) {
655+
if (request_and_thread.second.joinable())
656+
threads_to_join.push_back(std::move(request_and_thread.second));
657+
667658
request_and_thread.first.cancel();
668659

669660
if (request_and_thread.first.on_complete)
@@ -720,6 +711,12 @@ void OnionRequestRouter::_close_connections() {
720711
_path_rotation_schedule.clear();
721712
_pending_rotation_paths.clear();
722713
_update_status();
714+
715+
// Block until upload threads have finished
716+
for (auto& t : threads_to_join)
717+
if (t.joinable())
718+
t.join();
719+
723720
log::info(cat, "Closed all connections.");
724721
}
725722

src/network/session_network.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,17 @@ Network::~Network() {
260260

261261
_update_status(ConnectionStatus::disconnected);
262262
});
263+
264+
// Explicitly destroy in dependency order while _loop is still alive. Their destructors post
265+
// final cleanup via call_get so the loop must be running when they destruct.
266+
_router.reset();
267+
_snode_pool.reset();
268+
_transport.reset();
269+
270+
// Now shut down the loops (these destructors join their threads)
271+
_disk_loop.reset();
272+
_loop.reset();
273+
263274
log::debug(cat, "Destroyed.");
264275
}
265276

0 commit comments

Comments
 (0)