Skip to content

Commit

Permalink
bump req timeout for statedbproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Duchesneau committed Apr 27, 2021
1 parent dd4d6d7 commit 2a801a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions eosws/app/eosws/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (a *App) Run() error {
return fmt.Errorf("cannot parse statedb HTTP address: %w", err)
}

statedbProxy := rest.NewReverseProxy(stateHTTPURL, false, "REST API - Chain State", a.Config.StateDBHTTPProxyRetries)
statedbProxy := rest.NewReverseProxy(stateHTTPURL, false, "REST API - Chain State", a.Config.StateDBHTTPProxyRetries, time.Second*600)

var searchRouterClient pbsearch.RouterClient

Expand Down Expand Up @@ -401,7 +401,7 @@ func (a *App) Run() error {
return fmt.Errorf("cannot parse api-addr: %w", err)
}

dumbAPIProxy := rest.NewReverseProxy(apiURL, true, "REST API - Chain RPC", a.Config.NodeosRPCProxyRetries)
dumbAPIProxy := rest.NewReverseProxy(apiURL, true, "REST API - Chain RPC", a.Config.NodeosRPCProxyRetries, 30*time.Second)
billedDumbAPIProxy := dmetering.NewMeteringMiddleware(
dumbAPIProxy,
meter,
Expand Down
6 changes: 4 additions & 2 deletions eosws/rest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func deleteCORSHeaders(r *http.Request) {
}

type ReverseProxy struct {
timeoutPerReq time.Duration
retries int
target *url.URL
stripQuerystring bool
Expand All @@ -60,7 +61,7 @@ func (p *ReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {

func (p *ReverseProxy) tryReq(w http.ResponseWriter, r *http.Request, failDirectly bool) (written bool) {
begin := time.Now()
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
ctx, cancel := context.WithTimeout(r.Context(), p.timeoutPerReq)
defer cancel()

req := r.Clone(ctx)
Expand Down Expand Up @@ -201,8 +202,9 @@ func (p *ReverseProxy) tryReq(w http.ResponseWriter, r *http.Request, failDirect

}

func NewReverseProxy(target *url.URL, stripQuerystring bool, dmeteringKind string, retries int) http.Handler {
func NewReverseProxy(target *url.URL, stripQuerystring bool, dmeteringKind string, retries int, timeoutPerReq time.Duration) http.Handler {
return &ReverseProxy{
timeoutPerReq: timeoutPerReq,
retries: retries,
target: target,
stripQuerystring: stripQuerystring,
Expand Down

0 comments on commit 2a801a7

Please sign in to comment.