Upstream backport: libtorrent 9e3245e2bca092d6a344bad7ee7ce7836e0aecb0, "Keep user-added trackers flagged as extra when loading them from resume data." (Ivan, 2026-11-05, committed 2026-11-06, after the 0.16.27 tarball). https://github.com/rakshasa/libtorrent/commit/9e3245e2bca092d6a344bad7ee7ce7836e0aecb0 resume_load_tracker_settings() reloaded a tracker added at runtime with insert_url(group, url), so it came back without flag_extra_tracker. The next save wrote it without extra_tracker and group, and the load after that skipped it: a tracker added with d.tracker.insert lived through one restart. Measured on QTS 6.1 with 0.16.27: 230 trackers, 230, then 2. The commit also moves the throw for an unknown protocol from TrackerList::insert_url() to add_extra_tracker(), so a load skips an address it cannot use and d.tracker.insert still fails loudly. src/ only; its cppunit test is tests/libtorrent-upstream-1-9e3245e2bc-extra-tracker-resume.tests.patch. Verified with tools/tracker-list-test.sh (two restarts against the real binary) and tools/libtorrent-test.sh (D398). Retire at the first release that contains the commit (`patch -R --dry-run`). diff --git a/src/torrent/tracker/wrappers.cc b/src/torrent/tracker/wrappers.cc index 555acd97f9..7f4788d079 100644 --- a/src/torrent/tracker/wrappers.cc +++ b/src/torrent/tracker/wrappers.cc @@ -4,6 +4,7 @@ #include +#include "torrent/exceptions.h" #include "tracker/tracker_list.h" #include "tracker/tracker_controller.h" @@ -86,7 +87,8 @@ TrackerControllerWrapper::at(uint32_t index) const { void TrackerControllerWrapper::add_extra_tracker(uint32_t group, const std::string& url) { - m_ptr->tracker_list()->insert_url(group, url, true); + if (!m_ptr->tracker_list()->insert_url(group, url, true)) + throw input_error("could find matching tracker protocol (url:" + url + ")"); } uint32_t diff --git a/src/torrent/utils/resume.cc b/src/torrent/utils/resume.cc index b04cf00301..0c0a75f95e 100644 --- a/src/torrent/utils/resume.cc +++ b/src/torrent/utils/resume.cc @@ -526,7 +526,7 @@ resume_load_tracker_settings(Download download, const Object& object) { if (tracker_list->find_url(map.first) != tracker_list->end()) continue; - download.main()->tracker_list()->insert_url(map.second.get_key_value("group"), map.first); + download.main()->tracker_list()->insert_url(map.second.get_key_value("group"), map.first, true); } for (auto tracker : *tracker_list) { diff --git a/src/tracker/tracker_list.cc b/src/tracker/tracker_list.cc index ffa4bc21c5..3eefc368f7 100644 --- a/src/tracker/tracker_list.cc +++ b/src/tracker/tracker_list.cc @@ -265,7 +265,7 @@ TrackerList::insert(const tracker::Tracker& tracker) { } // TODO: Use proper flags for insert options. -void +bool TrackerList::insert_url(unsigned int group, const std::string& url, bool extra_tracker) { int flags = tracker::TrackerState::flag_enabled; @@ -301,13 +301,11 @@ TrackerList::insert_url(unsigned int group, const std::string& url, bool extra_t } else { LT_LOG("could find matching tracker protocol : url:%s", url.c_str()); - if (extra_tracker) - throw torrent::input_error("could find matching tracker protocol (url:" + url + ")"); - - return; + return false; } insert(tracker::Tracker(std::move(worker))); + return true; } TrackerList::iterator diff --git a/src/tracker/tracker_list.h b/src/tracker/tracker_list.h index 60ad568117..a474de021f 100644 --- a/src/tracker/tracker_list.h +++ b/src/tracker/tracker_list.h @@ -62,7 +62,7 @@ class LIBTORRENT_EXPORT TrackerList : private std::vector { void clear_stats(); iterator insert(const tracker::Tracker& tracker); - void insert_url(unsigned int group, const std::string& url, bool extra_tracker = false); + bool insert_url(unsigned int group, const std::string& url, bool extra_tracker = false); // TODO: Move these to controller / tracker.