Skip to content

Commit afe9ca1

Browse files
committed
Fix pedantic infohash concurrency check
1 parent 1a470fc commit afe9ca1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

client-tracker-announcer.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,27 @@ func (me *regularTrackerAnnounceDispatcher) init(client *Client) {
8181
me.logger = client.slogger
8282
me.announceData.Init(torrentTrackerAnnouncerKey.Compare)
8383
me.announceData.SetMinRecord(torrentTrackerAnnouncerKey{})
84+
// This is super pedantic, we're checking distinct root tables are synced with each other. In
85+
// this case there's a trigger in infohashAnnouncing to update all the corresponding infohashes
86+
// in announceData. Anytime announceData is changed, we check it's still up to date with
87+
// infohashAnnouncing.
8488
me.announceData.OnChange(func(old, new g.Option[indexed.Pair[torrentTrackerAnnouncerKey, nextAnnounceInput]]) {
8589
if !new.Ok {
8690
return
8791
}
88-
panicif.NotEq(
89-
new.Value.Right.infohashActive,
90-
g.OptionFromTuple(me.infohashAnnouncing.Get(new.Value.Left.ShortInfohash)).Value.count)
92+
// Due to trigger chains that result in announceData being updated *for unrelated fields*,
93+
// the check occurred prematurely while updating announceData. The fix is to update all
94+
// indexes, then to do triggers. This is massive overkill for this project right now.
95+
actual := new.Value.Right.infohashActive
96+
key := new.Value.Left
97+
expected := g.OptionFromTuple(me.infohashAnnouncing.Get(key.ShortInfohash)).Value.count
98+
if actual != expected {
99+
me.logger.Debug(
100+
"announceData.infohashActive != infohashAnnouncing.count",
101+
"key", key,
102+
"actual", actual,
103+
"expected", expected)
104+
}
91105
})
92106
me.announceIndex = indexed.NewFullMappedIndex(
93107
&me.announceData,

0 commit comments

Comments
 (0)