From 4eff65c7e7a3a0d227358f7dc3932b3004a99a15 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 9 Nov 2026 18:15:01 +0100 Subject: Move EVENT_COMPLETED out of the bucket lock, as the eventual syslog may be blocking (even if it's unlikely) --- src/trackerlogic.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/trackerlogic.c') diff --git a/src/trackerlogic.c b/src/trackerlogic.c index ddbc430..1f56a2c 100644 --- a/src/trackerlogic.c +++ b/src/trackerlogic.c @@ -78,7 +78,7 @@ void add_torrent_from_saved_state(ot_hash const hash, ot_time age, size_t down_c } size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount) { - int exactmatch, delta_torrentcount = 0; + int exactmatch, delta_torrentcount = 0, completed = 0; ot_torrent *torrent; ot_peer *peer_dest; ot_vector *torrents_list = mutex_bucket_lock_by_hash(*ws->hash); @@ -153,7 +153,7 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru if (OT_PEERFLAG(ws->peer) & PEER_FLAG_COMPLETED) { torrent->down_count++; - stats_issue_event(ws, EVENT_COMPLETED, 0, 0); + completed = 1; /* the event, which may syslog, is issued after unlock */ } if (OT_PEERFLAG(ws->peer) & PEER_FLAG_SEEDING) peer_list->seed_count++; @@ -180,7 +180,7 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru peer_list->seed_count++; if (!(OT_PEERFLAG_D(peer_dest, peer_size) & PEER_FLAG_COMPLETED) && (OT_PEERFLAG(ws->peer) & PEER_FLAG_COMPLETED)) { torrent->down_count++; - stats_issue_event(ws, EVENT_COMPLETED, 0, 0); + completed = 1; /* the event, which may syslog, is issued after unlock */ } if (OT_PEERFLAG_D(peer_dest, peer_size) & PEER_FLAG_COMPLETED) OT_PEERFLAG(ws->peer) |= PEER_FLAG_COMPLETED; @@ -190,12 +190,18 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru #ifdef WANT_SYNC if (proto == FLAG_MCA) { mutex_bucket_unlock_by_hash(*ws->hash, delta_torrentcount); + if (completed) + stats_issue_event(ws, EVENT_COMPLETED, 0, 0); return 0; } #endif ws->reply_size = return_peers_for_torrent(ws, torrent, amount, ws->reply, proto); mutex_bucket_unlock_by_hash(*ws->hash, delta_torrentcount); + + /* Issued after bucket unlock, so a slow syslog cannot stall the bucket */ + if (completed) + stats_issue_event(ws, EVENT_COMPLETED, 0, 0); return ws->reply_size; } -- cgit v1.3