Compare commits
2 commits
bc81ab84cb
...
46407b3685
Author | SHA1 | Date | |
---|---|---|---|
46407b3685 | |||
cd01f07007 |
2 changed files with 27 additions and 5 deletions
|
@ -71,7 +71,7 @@ func (h *Handler) Run(ctx context.Context) error {
|
|||
|
||||
defer func() {
|
||||
cancel()
|
||||
h.logger.Info("context canceled waiting for shutdown of components")
|
||||
h.logger.Info("context canceled, waiting for shutdown of components")
|
||||
wg.Wait()
|
||||
h.logger.Info("shutdown complete")
|
||||
}()
|
||||
|
|
|
@ -510,12 +510,34 @@ func (c *COBSFramer) WriteFrames(ctx context.Context, writer io.Writer, frameCha
|
|||
|
||||
encoded := c.encoder.Encode(frame)
|
||||
|
||||
n, err := io.Copy(writer, bytes.NewReader(encoded))
|
||||
err := c.writeRaw(ctx, writer, encoded)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cold not write data: %w", err)
|
||||
return err
|
||||
}
|
||||
|
||||
c.logger.Tracef("wrote %d bytes", n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *COBSFramer) writeRaw(ctx context.Context, writer io.Writer, raw []byte) error {
|
||||
errChan := make(chan error)
|
||||
|
||||
go func() {
|
||||
n, err := io.Copy(writer, bytes.NewReader(raw))
|
||||
if err != nil {
|
||||
errChan <- fmt.Errorf("could not write data: %w", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
c.logger.WithField("count", n).Tracef("wrote bytes")
|
||||
|
||||
close(errChan)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
case err := <-errChan:
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue