From 5dddd26918df671e1ea026a24138aafa50e86592 Mon Sep 17 00:00:00 2001 From: Mitchel Disveld Date: Mon, 4 Jan 2021 20:38:56 +0100 Subject: [PATCH] quick patch for negative workers --- surge/SurgeCore.go | 3 +++ surge/download.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/surge/SurgeCore.go b/surge/SurgeCore.go index f395f0f..6edaa4b 100644 --- a/surge/SurgeCore.go +++ b/surge/SurgeCore.go @@ -264,6 +264,9 @@ func WriteChunk(FileID string, ChunkID int32, Chunk []byte) { defer RecoverAndLog() workerCount-- + if workerCount < 0 { + workerCount = 0 + } fileInfo, err := dbGetFile(FileID) if err != nil { diff --git a/surge/download.go b/surge/download.go index 687684c..a5c52ff 100644 --- a/surge/download.go +++ b/surge/download.go @@ -198,6 +198,10 @@ func downloadChunks(file *File, randomChunks []int) { appendChunkLock.Unlock() workerCount-- + //TODO: Remove this clamp, dont double count timeouted arrivals + if workerCount < 0 { + workerCount = 0 + } //This file was not available at this time from this seeder, drop seeder for file. mutateSeederLock.Lock() @@ -271,6 +275,10 @@ func downloadChunks(file *File, randomChunks []int) { appendChunkLock.Unlock() workerCount-- + //TODO: Remove this clamp, dont double count timeouted arrivals + if workerCount < 0 { + workerCount = 0 + } //This file was not available at this time from this seeder, drop seeder for file. mutateSeederLock.Lock()