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()