pkg/gadgettracermanager: Check if Subscribe() returns a nil channel.
Subscribe() returns a nil channel if the stream was already closed.
Sadly, receiving from a nil channel never returns [1].
This commit checks if Subscribe() returns a nil channel and returns an error if
this is the case.
[1]
@@ -17,6 +17,7 @@ package gadgettracermanager
import (
"context"
"encoding/json"
+ "errors"
"fmt"
"runtime"
"sync"
@@ -87,6 +88,10 @@ func (g *GadgetTracerManager) ReceiveStream(tracerID *pb.TracerID, stream pb.Gad
g.mu.Unlock()
+ if ch == nil {
+ return errors.New("channel is nil, ranging over it will make us wait forever")
+ }
+
for l := range ch {
if l.EventLost {
ev := eventtypes.Event{
