Skip to content

Commit

Permalink
don't announce stopped-event to websocket trackers. This (appears) to…
Browse files Browse the repository at this point in the history
… solve a shutdown stall where we send stopped-announces after aborting outstanding announces (including the persistent websocket connection). The announec causes the persistent connection to be re-established and sometimes not torn down properly again, to complete the shut down
  • Loading branch information
arvidn committed Feb 1, 2021
1 parent ec22c1b commit 4e796f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5845,12 +5845,13 @@ namespace {
}

#if TORRENT_USE_RTC
void torrent::generate_rtc_offers(int count
, std::function<void(error_code const&, std::vector<aux::rtc_offer>)> handler)
void torrent::generate_rtc_offers(int const count
, std::function<void(error_code const&, std::vector<aux::rtc_offer>)> handler)
{
// rtc_signaling is created lazily
if(!m_rtc_signaling)
if (!m_rtc_signaling)
{
TORRENT_ASSERT(count > 0);
m_rtc_signaling = std::make_shared<aux::rtc_signaling>(m_ses.get_context()
, this
, std::bind(&torrent::on_rtc_stream, this, _1));
Expand Down
16 changes: 13 additions & 3 deletions src/tracker_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ namespace libtorrent::aux {
if (m_abort && req.event != event_t::stopped) return;

#ifndef TORRENT_DISABLE_LOGGING
if(auto cb = c.lock())
if (auto cb = c.lock())
cb->debug_log("*** QUEUE_TRACKER_REQUEST [ listen_port: %d ]", req.listen_port);
#endif

Expand Down Expand Up @@ -305,16 +305,26 @@ namespace libtorrent::aux {
else if (protocol == "ws" || protocol == "wss")
{
std::shared_ptr<request_callback> cb = c.lock();
if(!cb) return;
if (!cb) return;

// TODO: introduce a setting for max_offers
const int max_offers = 10;
req.num_want = std::min(req.num_want, max_offers);
if (req.num_want == 0)
{
// when we're shutting down, we don't really want to
// re-establish the persistent websocket connection just to
// announce "stopped", and advertize 0 offers. It may hang
// shutdown.
post(ios, std::bind(&request_callback::tracker_request_error, cb, std::move(req)
, errors::torrent_aborted, operation_t::connect
, "", seconds32(0)));
}
cb->generate_rtc_offers(req.num_want
, [this, &ios, req = std::move(req), c](error_code const& ec
, std::vector<aux::rtc_offer> offers) mutable
{
if(!ec) req.offers = std::move(offers);
if (!ec) req.offers = std::move(offers);

auto it = m_websocket_conns.find(req.url);
if (it != m_websocket_conns.end() && it->second->is_started()) {
Expand Down

0 comments on commit 4e796f3

Please sign in to comment.