Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading from a closed body in case of a network error during body read #656

Open
markvai opened this issue Feb 1, 2024 · 0 comments
Open

Comments

@markvai
Copy link

markvai commented Feb 1, 2024

What happened?

We got this error when using the client:

unexpected EOF: file already closed

What did you expect to happen?

We don't expect to see file already closed errors.

How can we reproduce it (as minimally and precisely as possible)?

This is sporadic and can happen when reading from the http response body after a valid response status was received.

The root cause here it's possible that an error is returned while reading the response body, like here:

go-jira/cloud/jira.go

Lines 249 to 250 in 50d59fe

defer httpResp.Body.Close()
err = json.NewDecoder(httpResp.Body).Decode(v)

So while decoding there is a network error and the read fails, not the body is closed on defer.

Than the error is passed to:

err = NewJiraError(resp, err)

And there, it is expected that the body was not closed/read already, so it tries to read again from the body:

go-jira/cloud/error.go

Lines 25 to 26 in 50d59fe

defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)

As a result we get a confusing error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant