You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like the retries with POST used in a hystrix client run into some error related to the request being already used. Error returned from http call is "{"status":"Post "http://localhost:8080/sampleLookup\": http: ContentLength=14 with Body length 0"}", which seems incorrect - we shouldn't run into an issue of request being reused several times.
Did anyone encounter this?
Thanks!
Source code following, curl command under the code.
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"time"
hystrix "github.com/gojek/heimdall/v7/hystrix"
)
type SampleRequest struct {
String string `json:"string"`
}
type SampleResponse struct {
Status string `json:"status"`
}
func initialEndpoint(w http.ResponseWriter, r *http.Request) {
var sampleRequest SampleRequest
// hystrix client
client := hystrix.NewClient(
hystrix.WithHystrixTimeout(1000*time.Millisecond),
hystrix.WithRetryCount(3),
)
// request buffer
var buf bytes.Buffer
_ = json.NewEncoder(&buf).Encode(sampleRequest)
// send request
headers := http.Header{}
headers.Set("Content-Type", "application/json")
res, err := client.Post("http://localhost:8080/sampleLookup", &buf, headers)
// interpret response
if err != nil {
sampleResponse := SampleResponse{
Status: err.Error(),
}
json.NewEncoder(w).Encode(sampleResponse)
return
}
body, _ := ioutil.ReadAll(res.Body)
json.NewEncoder(w).Encode(body)
res.Body.Close()
}
// just wait for 3 sec
func sampleLookup(w http.ResponseWriter, r *http.Request) {
time.Sleep(3 * time.Second)
json.NewEncoder(w).Encode(SampleResponse{
Status: "ok",
})
}
// start server with 2 endpoints
func main() {
http.HandleFunc("/initialEndpoint", initialEndpoint)
http.HandleFunc("/sampleLookup", sampleLookup)
log.Fatal(http.ListenAndServe(":8080", nil))
}
It looks like the retries with POST used in a hystrix client run into some error related to the request being already used. Error returned from http call is "{"status":"Post "http://localhost:8080/sampleLookup\": http: ContentLength=14 with Body length 0"}", which seems incorrect - we shouldn't run into an issue of request being reused several times.
Did anyone encounter this?
Thanks!
Source code following, curl command under the code.
Curl command:
The text was updated successfully, but these errors were encountered: