From 8ee0fd88dc9072b89a6643173f400453e38d3a7b Mon Sep 17 00:00:00 2001 From: Nguyen Marc Date: Wed, 1 Nov 2023 02:35:40 +0100 Subject: [PATCH] fix(fc2): pass error canceled, which triger the end of errgroup --- fc2/fc2.go | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/fc2/fc2.go b/fc2/fc2.go index 8e7f6e4..7c1e4b9 100644 --- a/fc2/fc2.go +++ b/fc2/fc2.go @@ -233,18 +233,15 @@ func (f *FC2) HandleWS( g, ctx := errgroup.WithContext(ctx) g.Go(func() error { - if err := ws.HeartbeatLoop(ctx, conn, msgChan); err != nil { - if err == io.EOF { - f.log.Info().Msg("healthcheck finished") - return err - } else if errors.Is(err, context.Canceled) { - f.log.Info().Msg("healthcheck canceled") - } else { - f.log.Error().Err(err).Msg("healthcheck failed") - return err - } + err := ws.HeartbeatLoop(ctx, conn, msgChan) + if err == io.EOF { + f.log.Info().Msg("healthcheck finished") + } else if errors.Is(err, context.Canceled) { + f.log.Info().Msg("healthcheck canceled") + } else { + f.log.Error().Err(err).Msg("healthcheck failed") } - return nil + return err }) g.Go(func() error { @@ -262,9 +259,8 @@ func (f *FC2) HandleWS( f.log.Info().Msg("ws listen canceled") } else { f.log.Error().Err(err).Msg("ws listen failed") - return err } - return nil + return err }) g.Go(func() error { @@ -283,14 +279,12 @@ func (f *FC2) HandleWS( } if err == io.EOF { f.log.Info().Msg("download stream finished") - return err } else if errors.Is(err, context.Canceled) { f.log.Info().Msg("download stream canceled") } else { f.log.Error().Err(err).Msg("download stream failed") - return err } - return nil + return err }) if f.params.WriteChat { @@ -304,14 +298,12 @@ func (f *FC2) HandleWS( if err == io.EOF { f.log.Info().Msg("download chat finished") - return err } else if errors.Is(err, context.Canceled) { f.log.Info().Msg("download chat canceled") } else { f.log.Error().Err(err).Msg("download chat failed") - return err } - return nil + return err }) }