Skip to content

Commit e076b20

Browse files
committed
fix(job): scanner buffer
1 parent 7c20a86 commit e076b20

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

services/runners/running_job.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,33 @@ func (p *runningJob) logPipe(reader io.Reader) {
9696
defer p.logWG.Done()
9797

9898
scanner := bufio.NewScanner(reader)
99+
const maxCapacity = 10 * 1024 * 1024 // 10 MB
100+
buf := make([]byte, maxCapacity)
101+
scanner.Buffer(buf, maxCapacity)
99102

100103
for scanner.Scan() {
101104
line := scanner.Text()
102105
p.Log(line)
103106
}
104107

105-
if scanner.Err() != nil && scanner.Err().Error() != "EOF" {
106-
//don't panic on these errors, sometimes it throws not dangerous "read |0: file already closed" error
107-
log.WithError(scanner.Err()).WithFields(log.Fields{
108-
"context": "task_log",
109-
"task_id": p.job.Task.ID,
110-
}).Debug("failed to read log")
108+
msg := "Failed to read TaskRunner output"
109+
110+
switch scanner.Err().Error() {
111+
case "EOF",
112+
"os: process already finished",
113+
"read |0: file already closed":
114+
return // it is ok
115+
case "bufio.Scanner: token too long":
116+
msg = "TaskRunner output exceeds the maximum allowed size of 10MB"
117+
break
111118
}
119+
120+
p.job.Kill() // kill the job because stdout cannot be read.
121+
122+
log.WithError(scanner.Err()).WithFields(log.Fields{
123+
"task_id": p.job.Task.ID,
124+
"context": "job",
125+
}).Error(msg)
126+
127+
p.Log("Fatal error: " + msg)
112128
}

0 commit comments

Comments
 (0)