Skip to content

Commit

Permalink
Fix flaky HTTP requests due to bug with net/http and io.Pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
isobit committed Sep 20, 2023
1 parent 41cc3f5 commit 076d77b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion schemes/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,16 @@ func Connect(cfg ndog.ConnectConfig) error {
return ConnectJSON(cfg)
}

// net/http hangs when io.Pipe is used as request body so collect it all
// into a simple buffer reader.
// https://github.com/golang/go/issues/29246
body, err := io.ReadAll(cfg.Stream.Reader)
if err != nil {
return err
}

// Convert to HTTP request
httpReq, err := http.NewRequest(opts.Method, cfg.URL.String(), cfg.Stream.Reader)
httpReq, err := http.NewRequest(opts.Method, cfg.URL.String(), bytes.NewReader(body))
if err != nil {
return err
}
Expand Down

0 comments on commit 076d77b

Please sign in to comment.