Skip to content

Commit

Permalink
fix: bufio.Scanner: token too long
Browse files Browse the repository at this point in the history
close #98
  • Loading branch information
ncarlier committed Aug 18, 2024
1 parent 0c41f76 commit 8f8e69f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pkg/hook/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,17 @@ func (job *Job) Run() error {

// Write script output to log file and the work message channel
go func(reader io.Reader) {
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
line := scanner.Text()
r := bufio.NewReader(reader)
for {
line, err := r.ReadString('\n')
if err != nil {
if err == io.EOF {
break
}
slog.Error("error while reading hook std[out/err]", "hook", job.name, "id", job.id, "err", err)
break
}
line, _ = strings.CutSuffix(line, "\r")
// writing to the work channel
if !job.IsTerminated() {
job.MessageChan <- []byte(line)
Expand All @@ -266,9 +274,6 @@ func (job *Job) Run() error {
break
}
}
if err := scanner.Err(); err != nil {
slog.Error("hook is unable to read script stdout", "hook", job.name, "id", job.id, "err", err)
}
wg.Done()
}(cmdReader)

Expand Down

0 comments on commit 8f8e69f

Please sign in to comment.