Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Http response got EOF error with correct body occasionally #223

Closed
pengisgood opened this issue Aug 6, 2020 · 3 comments
Closed

Http response got EOF error with correct body occasionally #223

pengisgood opened this issue Aug 6, 2020 · 3 comments
Labels
need/triage Needs initial labeling and prioritization

Comments

@pengisgood
Copy link
Contributor

pengisgood commented Aug 6, 2020

When I debug in the following code, sometimes it can read data from the body correctly but with EOF error.

func (r *trailerReader) Read(b []byte) (int, error) {
	n, err := r.resp.Body.Read(b)
	if err != nil {
		if e := r.resp.Trailer.Get("X-Stream-Error"); e != "" {
			err = errors.New(e)
		}
	}
	return n, err
}

I called this method in my code:

// FilesRead read a file in a given MFS
func (s *Shell) FilesRead(ctx context.Context, path string, options ...FilesOpt) (io.ReadCloser, error) {
	rb := s.Request("files/read", path)
	for _, opt := range options {
		if err := opt(rb); err != nil {
			return nil, err
		}
	}

	resp, err := rb.Send(ctx)
	if err != nil {
		return nil, err
	}
	if resp.Error != nil {
		return nil, resp.Error
	}

	return resp.Output, nil
}

Any thoughts?

@pengisgood pengisgood added the need/triage Needs initial labeling and prioritization label Aug 6, 2020
@Stebalien
Copy link
Member

This is normal: https://golang.org/pkg/io/#Reader (paragraph 3).

@Stebalien
Copy link
Member

(not that I agree with go's choices here..., but it's normal)

@pengisgood
Copy link
Contributor Author

Thanks for the response. Yea, it's weird. 😞

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

2 participants