Skip to content

Commit

Permalink
bug(executor): Log lines not copied correctly
Browse files Browse the repository at this point in the history
When saving the log lines from zap we need to copy the `[]byte` we
get otherwise weird things can happen. Without doing this we would
lose some of the log information.
  • Loading branch information
symbiont-daniel-gustafsson committed Jan 19, 2021
1 parent 90be9c3 commit 99fd6cb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ func (_ *LogWriter) Sync() error {

func (lw *LogWriter) Write(p []byte) (n int, err error) {
if len(p) > 0 {
// make a copy of the line so that it doesn't get changed later
line := make([]byte, len(p))
copy(line, p)

// we remove last byte since it is an newline
lw.current = append(lw.current, p[:len(p)-1])
lw.current = append(lw.current, line[:len(line)-1])
}
return len(p), nil
}
Expand Down Expand Up @@ -300,18 +304,18 @@ func NewExecutor(testId lib.TestId, marshaler lib.Marshaler, logger *zap.Logger,
func (e *Executor) Deploy(srv *http.Server) {
DeployWithComponentUpdate(srv, e.topology, e.marshaler, func(name string) StepInfo {
buffer, ok := e.buffers[name]
logs := make([]string, 0)
if ok {
logs := make([]string, 0, len(buffer.current))
for _, l := range buffer.current {
logs = append(logs, string(l))
}
buffer.current = make([][]byte, 0)
} else {
panic(fmt.Sprintf("Couldn't find buffer for %s", name))
}
return StepInfo{
LogLines: logs,
return StepInfo{
LogLines: logs,
}
}

panic(fmt.Sprintf("Couldn't find buffer for %s", name))
})
}

Expand Down

0 comments on commit 99fd6cb

Please sign in to comment.