go-jira icon indicating copy to clipboard operation
go-jira copied to clipboard

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

Open markvai opened this issue 1 year ago • 0 comments

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.

markvai avatar Feb 01 '24 14:02 markvai