Skip to content

atc: Have EOF errors from checks treated as no versions found - #9639

Merged
taylorsilva merged 1 commit into
masterfrom
check-eof-errors
Jul 14, 2026
Merged

taylorsilva merged 1 commit into
masterfrom
check-eof-errors

Conversation

@taylorsilva

@taylorsilva taylorsilva commented Jul 9, 2026 •

Copy link
Copy Markdown
Member

Changes proposed by this PR

I got the intermittent and randomly occurring run check: EOF error in our CI, which marks the resource as "errored" with an orange outline on the resource and an orange triangle on the pipeline's card. I decided to look at where the error came from again. It starts here:

return false, fmt.Errorf("run check: %w", runErr)

and leads us into this function:

func (resource Resource) run(ctx context.Context, container runtime.Container, spec runtime.ProcessSpec, stderr io.Writer, attach bool, output any) (runtime.ProcessResult, error) {
input, err := resource.Signature()
if err != nil {
return runtime.ProcessResult{}, err
}
buf := new(bytes.Buffer)
io := runtime.ProcessIO{
Stdin: bytes.NewBuffer(input),
Stdout: buf,
Stderr: stderr,
}
var process runtime.Process
if attach {
process, err = attachOrRun(ctx, container, spec, io)
} else {
process, err = container.Run(ctx, spec, io)
}
if err != nil {
return runtime.ProcessResult{}, err
}
result, err := process.Wait(ctx)
if err != nil {
return runtime.ProcessResult{}, err
}
if result.ExitStatus != 0 {
return result, nil
}
if err := json.NewDecoder(buf).Decode(output); err != nil {
return runtime.ProcessResult{}, err
}
return result, nil
}

This also got me looking at the io.EOF code in Go stdlib and noticed that it says:

// Functions should return EOF only to signal a graceful end of input.

That got me looking at the Decode() function here:

if err := json.NewDecoder(buf).Decode(output); err != nil {

I wondered if it's meant to return io.EOF in the way described in the previous comment, and it does! The godocs have an example showing how the decoder parses one JSON object at a time and returns EOF when it's done parsing: https://pkg.go.dev/encoding/json#Decoder

Us immediately getting EOF just means there was no data on Stdout to parse. Given that we only hit this when the check already exited with an exit code of zero, I think we can infer that the check had nothing to return. If we only got a partial data read, we'd get a more detailed error from the decoder. In my tests of the decoder I can see that partial reads of JSON objects results in errors like invalid character....

Still don't know why this error happens at all. Resources are supposed to emit empty json arrays [] if they found nothing. I wonder if such a short string ends up not getting flushed by the container runtime before we try decoding it, assuming there is a buffer to flush. We never see this error on put or get steps, so this seems like a likely cause.

I added some extra checks in the Get() and Put() functions that also call this private run(). In these cases we want to detect if we get back a null version and then error since it's always invalid for either of these scripts to not return a version. The put already had a check like this, but only when the exit status was zero. Now both functions will return early if the exit status is zero, and return an error if no version was emitted.

I got the `run check: EOF` error in our CI and decided to look at where
the error came from again. That got me looking at the `io.EOF` code in
Go stdlib and noticed that it says:

```
// Functions should return EOF only to signal a graceful end of input.
```

That got me looking at the `Decode()` function to see if it's meant to
return `io.EOF` in this way, and it does! The godocs have an example
showing how the decoder parses one JSON object at a time and returns
`EOF` when it's done parsing: https://pkg.go.dev/encoding/json#Decoder

Us immediately getting EOF just means there was no data on Stdout to
parse. Given that we only hit this when the check already exited with an
exit code of zero, I think we can infer that the check had nothing to
return. If we only got a partial data read, we'd get a more detailed
error from the decoder. In my tests of the decoder I can see that
partial reads of JSON objects results in errors like `invalid
character...`.

Still don't know why this error happens at all. Resources are supposed
to emit empty json arrays `[]` if they found nothing. I wonder if such a
short string ends up not getting flushed by the container runtime before
we try decoding it?

I added some extra checks in the `Get()` and `Put()` functions that also
call this private `run()`. In these cases we want to detect if we get
back a null version and error, since it's always invalid for either of
these scripts to not return a version. The put already had a check like
this, but only when the exit status was zero. Now both functions will
return early if the exit status is zero, and return an error if no
version was emitted.

Signed-off-by: Taylor Silva <[email protected]>
@taylorsilva
taylorsilva requested a review from a team July 9, 2026 23:17
@taylorsilva
taylorsilva merged commit 41b405e into master Jul 14, 2026
11 checks passed
@taylorsilva
taylorsilva deleted the check-eof-errors branch July 14, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant