Skip to content

Commit 12ff0eb

Browse files
committed
[DHT] Fix segfault after shutdown before full sync
1 parent 3b64fce commit 12ff0eb

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/dht/session.cpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,7 @@ void StopTorrentDHTNetwork()
462462
{
463463
LogPrintf("%s --Begin stopping all DHT session threads.\n", __func__);
464464
fRun = false;
465-
if (pDHTTorrentThread != NULL)
466-
{
465+
if (pDHTTorrentThread != nullptr) {
467466
size_t nRunningThreads = fMultiThreads ? nThreads : 1;
468467
LogPrint("dht", "DHTTorrentNetwork -- StopTorrentDHTNetwork trying to stop.\n");
469468
if (fStarted) {
@@ -486,21 +485,26 @@ void StopTorrentDHTNetwork()
486485
pairSession.second->Session->apply_settings(params.settings);
487486
pairSession.second->Session->abort();
488487
}
489-
488+
} else {
489+
MilliSleep(1001);
490490
}
491+
491492
pDHTTorrentThread->join();
492-
// join all DHT threads
493-
if (fMultiThreads) {
494-
for (unsigned int i = 0; i < nThreads; i++) {
495-
std::pair<std::shared_ptr<std::thread>, std::shared_ptr<CHashTableSession>> pairSession = arraySessions[i];
493+
494+
if (fStarted) {
495+
// join all DHT threads
496+
if (fMultiThreads) {
497+
for (unsigned int i = 0; i < nThreads; i++) {
498+
std::pair<std::shared_ptr<std::thread>, std::shared_ptr<CHashTableSession>> pairSession = arraySessions[i];
499+
pairSession.first->join();
500+
}
501+
} else {
502+
std::pair<std::shared_ptr<std::thread>, std::shared_ptr<CHashTableSession>> pairSession = arraySessions[0];
496503
pairSession.first->join();
497504
}
498-
} else {
499-
std::pair<std::shared_ptr<std::thread>, std::shared_ptr<CHashTableSession>> pairSession = arraySessions[0];
500-
pairSession.first->join();
501505
}
502506
}
503-
507+
504508
if (fReannounceStarted) {
505509
// Stop ReannounceEntries
506510
fReannounceStarted = false;

0 commit comments

Comments
 (0)