From cb8d47879a9ea9b9135edffe40a11b5f3c55b471 Mon Sep 17 00:00:00 2001 From: ersonp Date: Tue, 25 Jan 2022 14:33:00 +0530 Subject: [PATCH 1/2] Fix close log This commit fixes the closing logs in the genericClient for all transports. Now we check if the client is closed and if ther error is either ErrClosedPipe or use of closed network connection and print a info log instead of a warn log. --- pkg/transport/network/client.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/transport/network/client.go b/pkg/transport/network/client.go index d15a323c39..ba6bbf9ce8 100644 --- a/pkg/transport/network/client.go +++ b/pkg/transport/network/client.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net" + "strings" "sync" "github.com/skycoin/dmsg" @@ -150,6 +151,12 @@ func (c *genericClient) acceptTransports(lis net.Listener) { if errors.Is(err, io.EOF) { continue // likely it's a dummy connection from service discovery } + + if c.isClosed() && (errors.Is(err, io.ErrClosedPipe) || strings.Contains(err.Error(), "use of closed network connection")) { + c.log.Info("Cleanly stopped serving.") + return + } + c.log.Warnf("failed to accept incoming connection: %v", err) if !handshake.IsHandshakeError(err) { c.log.Warnf("stopped serving") From 96118c9eb43084d5b0c6fc43dc5459f7431e07b6 Mon Sep 17 00:00:00 2001 From: ersonp Date: Tue, 25 Jan 2022 14:45:47 +0530 Subject: [PATCH 2/2] Fix autoconnector logs This commit fixes autoconnector logs by printing the warn log only if ther error is not io.ErrClosedPipe. --- pkg/servicedisc/autoconnect.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/servicedisc/autoconnect.go b/pkg/servicedisc/autoconnect.go index 5b6b79d299..26f5aa25d5 100644 --- a/pkg/servicedisc/autoconnect.go +++ b/pkg/servicedisc/autoconnect.go @@ -2,6 +2,8 @@ package servicedisc import ( "context" + "errors" + "io" "net/http" "time" @@ -81,7 +83,9 @@ func (a *autoconnector) Run(ctx context.Context) (err error) { a.log.WithField("pk", pk).WithField("attempt", val).Debugln("Trying to add transport to public visor") logger := a.log.WithField("pk", pk).WithField("type", string(network.STCPR)) if err = a.tryEstablishTransport(ctx, pk, logger); err != nil { - logger.WithError(err).Warnln("Failed to add transport to public visor") + if !errors.Is(err, io.ErrClosedPipe) { + logger.WithError(err).Warnln("Failed to add transport to public visor") + } failedAddresses[pk]++ continue }