Repository navigation
atc: Have EOF errors from checks treated as no versions found - #9639
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed by this PR
I got the intermittent and randomly occurring
run check: EOFerror 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:concourse/atc/exec/check_step.go
Line 216 in 2bddebe
and leads us into this function:
concourse/atc/resource/resource.go
Lines 125 to 160 in 2bddebe
This also got me looking at the
io.EOFcode in Go stdlib and noticed that it says:That got me looking at the
Decode()function here:concourse/atc/resource/resource.go
Line 156 in 2bddebe
I wondered if it's meant to return
io.EOFin 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 returnsEOFwhen it's done parsing: https://pkg.go.dev/encoding/json#DecoderUs 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()andPut()functions that also call this privaterun(). 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. Theputalready 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.