From 1c03afd63b6c7706a8abc3faf131a836a04cf06d Mon Sep 17 00:00:00 2001 From: Kleissner Date: Sun, 25 Apr 2021 00:07:53 +0200 Subject: [PATCH] Fix: Check if channel is closed. --- dht/Information Request.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dht/Information Request.go b/dht/Information Request.go index fe15f81..3d8aca8 100644 --- a/dht/Information Request.go +++ b/dht/Information Request.go @@ -51,7 +51,11 @@ func (dht *DHT) NewInformationRequest(Action int, Key []byte, Nodes []*Node) (ir func (ir *InformationRequest) CollectResults(timeout time.Duration) (results []*NodeMessage) { for { select { - case result := <-ir.ResultChan: + case result, ok := <-ir.ResultChan: + if !ok { // channel closed? + return + } + results = append(results, result) case <-time.After(timeout):