Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Commit

Permalink
Check lenght of log parts when parsing the log stream
Browse files Browse the repository at this point in the history
**What**
- Add a check to ensure that there are 3 log parts, this case should
never happen, but is now more clearly documented for developers

Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler authored and alexellis committed Jul 31, 2019
1 parent 15e8ed8 commit f5f6aa8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions handlers/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ func parseLogStream(ctx context.Context, name string, msgStream chan logs.Messag
rawMsg := string(bytes.Trim(scanner.Bytes()[stdWriterPrefixLen:], "\x00"))
logParts := strings.SplitN(rawMsg, " ", 3)

// this should never happen because every log line should have a `Timestamp ServiceDetails RawMsg`,
// the Docker API ensures the Timestamp and ServiceDetails will not be empty and even when
// the raw message is an empty string, logParts will correctly have an empty string for the
// third part. If there are not 3 parts, then there has been an Docker API failure
if len(logParts) != 3 {
log.Printf("parseLogStream: failed to parse log message, unexpected number of parts: '%s'", rawMsg)
return
}

ts, err := time.Parse(time.RFC3339Nano, logParts[0])
if err != nil {
log.Printf("parseLogStream: failed to parse timestamp: %sn", err)
Expand Down

0 comments on commit f5f6aa8

Please sign in to comment.