From def220daf35d9da49fb8a1693729f5caa6981306 Mon Sep 17 00:00:00 2001 From: Saxon Date: Sun, 10 Mar 2019 12:34:45 +1030 Subject: [PATCH] revid: sending encode errors to errorHandler and made multiSender smarter Errors captured from encoding are now sent to the error handler. We also made multiSender smart so that during a write if sendRetry is on, we first check that revid is actually running before attempting to send again. If revid is not running we return. We also now log any send errors inside multiSender. --- revid/revid.go | 6 +++--- revid/senders.go | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index 600d46c5..087cbbfa 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -450,16 +450,16 @@ loop: // Get bytes from the chunk. bytes := chunk.Bytes() + // Loop over encoders and hand bytes over to each one. for _, enc := range r.encoder { err := enc.Encode(bytes) if err != nil { - fmt.Printf("encode error: %v", err) - // TODO: deal with this error + r.err <- err } } - // Release the chunk back to the ring buffer + // Release the chunk back to the ring buffer. chunk.Close() // FIXME(saxon): this doesn't work anymore. diff --git a/revid/senders.go b/revid/senders.go index 34662ccf..2d7ebf24 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -70,11 +70,15 @@ func newMultiSender(owner *Revid, senders []loadSender) *multiSender { func (s *multiSender) Write(d []byte) (int, error) { for i, sender := range s.senders { sender.load(d) - s.owner.config.Logger.Log(logger.Debug, fmt.Sprintf("sending to output: %d", i)) + s.owner.config.Logger.Log(logger.Debug, "sending to output", "output", i) err := sender.send() if err != nil { + if !s.owner.IsRunning() { + return 0, err + } if s.owner.config.SendRetry { for err != nil { + s.owner.config.Logger.Log(logger.Warning, "send failed", "output", i, "error", err) sender.handleSendFail(err) err = sender.send() }