Skip to content

Commit 9a2c994

Browse files
committed
fix(tasks): stop process if stdout is broken
1 parent 7ebf9e8 commit 9a2c994

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

services/tasks/TaskRunner_logging.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ func (t *TaskRunner) logPipe(reader io.Reader) {
153153
}()
154154

155155
scanner := bufio.NewScanner(reader)
156+
//const maxCapacity = 10 * 1024 * 1024 // 10 MB
157+
//buf := make([]byte, maxCapacity)
158+
//scanner.Buffer(buf, maxCapacity)
156159

157160
for scanner.Scan() {
158161
line := scanner.Text()
@@ -161,7 +164,28 @@ func (t *TaskRunner) logPipe(reader io.Reader) {
161164

162165
close(linesCh)
163166

164-
if scanner.Err() != nil && scanner.Err().Error() != "EOF" {
165-
util.LogDebugF(scanner.Err(), log.Fields{"error": "Failed to read TaskRunner output"})
167+
if scanner.Err() != nil {
168+
if scanner.Err().Error() == "EOF" {
169+
return // it is ok
170+
}
171+
172+
msg := "Failed to read TaskRunner output"
173+
174+
switch scanner.Err().Error() {
175+
case "EOF":
176+
return // it is ok
177+
case "bufio.Scanner: token too long":
178+
msg = "TaskRunner output exceeds the maximum allowed size of 10MB"
179+
break
180+
}
181+
182+
t.kill() // kill the job because stdout cannot be read.
183+
184+
log.WithError(scanner.Err()).WithFields(log.Fields{
185+
"task_id": t.Task.ID,
186+
"context": "task_logger",
187+
}).Error(msg)
188+
189+
t.Log("Fatal error: " + msg)
166190
}
167191
}

0 commit comments

Comments
 (0)