andygrunwald / go-jira

Go client library for Atlassian Jira
https://pkg.go.dev/github.com/andygrunwald/go-jira?tab=doc
MIT License
1.47k stars 469 forks source link

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

Open markvai opened 8 months ago

markvai commented 8 months ago

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: https://github.com/andygrunwald/go-jira/blob/50d59fe116d6b0d7156e4129be4963b910c60c11/cloud/jira.go#L249-L250

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: https://github.com/andygrunwald/go-jira/blob/50d59fe116d6b0d7156e4129be4963b910c60c11/cloud/issue.go#L1084

And there, it is expected that the body was not closed/read already, so it tries to read again from the body: https://github.com/andygrunwald/go-jira/blob/50d59fe116d6b0d7156e4129be4963b910c60c11/cloud/error.go#L25-L26

As a result we get a confusing error.