Skip to content

Commit

Permalink
graphql: add query timeout (#26116)
Browse files Browse the repository at this point in the history
This PR adds a 60 second timeout to graphql queries.
  • Loading branch information
ahmetavc authored Nov 8, 2022
1 parent 9139734 commit ee9ff06
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion graphql/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package graphql

import (
"context"
"encoding/json"
"net/http"
"time"

"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/internal/ethapi"
Expand All @@ -41,7 +43,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

response := h.Schema.Exec(r.Context(), params.Query, params.OperationName, params.Variables)
ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
defer cancel()

response := h.Schema.Exec(ctx, params.Query, params.OperationName, params.Variables)
responseJSON, err := json.Marshal(response)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down

0 comments on commit ee9ff06

Please sign in to comment.