docker-log-driver-test icon indicating copy to clipboard operation
docker-log-driver-test copied to clipboard

Shouldn't it continue when failed to decode a msg when consuming from the input protobuf stream

Open fivesheep opened this issue 6 years ago • 1 comments

For this piece of code, when dec.ReadMsg has error and the error is not io.EOF, shall it skip to the next iteration with continue after the line a new decoder was created?

https://github.com/cpuguy83/docker-log-driver-test/blob/master/driver.go#L95-L102

	for {
		if err := dec.ReadMsg(&buf); err != nil {
			if err == io.EOF {
				logrus.WithField("id", lf.info.ContainerID).WithError(err).Debug("shutting down log logger")
				lf.stream.Close()
				return
			}
			dec = protoio.NewUint32DelimitedReader(lf.stream, binary.BigEndian, 1e6)
		}
		var msg logger.Message
		msg.Line = buf.Line
		msg.Source = buf.Source
		msg.Partial = buf.Partial
		msg.Timestamp = time.Unix(0, buf.TimeNano)

		if err := lf.l.Log(&msg); err != nil {
			logrus.WithField("id", lf.info.ContainerID).WithError(err).WithField("message", msg).Error("error writing log message")
			continue
		}

		buf.Reset()
}

fivesheep avatar Mar 10 '18 09:03 fivesheep

Indeed it should.

cpuguy83 avatar Mar 10 '18 11:03 cpuguy83