From caa7db0f7752a4fe35fee74618c2674277b4fb43 Mon Sep 17 00:00:00 2001 From: Mathieu Lecarme Date: Mon, 20 Jun 2022 17:12:45 +0200 Subject: [PATCH] Fix: it's ok to stop the connection. --- pkg/acquisition/modules/loki/loki.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/acquisition/modules/loki/loki.go b/pkg/acquisition/modules/loki/loki.go index 281bb8ed8..ae0339d75 100644 --- a/pkg/acquisition/modules/loki/loki.go +++ b/pkg/acquisition/modules/loki/loki.go @@ -12,6 +12,7 @@ import ( "fmt" "io" "io/ioutil" + "net" "net/http" "net/url" "time" @@ -346,6 +347,13 @@ func (l *LokiSource) StreamingAcquisition(out chan types.Event, t *tomb.Tomb) er }() c, res, err := l.dialer.DialContext(ctx, l.lokiWebsocket, l.header) if err != nil { + if oerr, ok := err.(*net.OpError); ok && oerr.Err.Error() == "operation was canceled" { + // it's ok, the websocket connection is closed by the client, triggered by the tomb, lets stop + return nil + } + if res == nil { // no body, it's a network error, not a HTTP error + return errors.Wrap(err, "loki OneShotAcquisition error before HTTP stack") + } buf, err2 := ioutil.ReadAll(res.Body) if err2 == nil { return fmt.Errorf("loki websocket (%s) error %v : %s", l.lokiWebsocket, err, string(buf))