Skip to content

Commit ee9ff06

Browse files
authored
graphql: add query timeout (#26116)
This PR adds a 60 second timeout to graphql queries.
1 parent 9139734 commit ee9ff06

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

graphql/service.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package graphql
1818

1919
import (
20+
"context"
2021
"encoding/json"
2122
"net/http"
23+
"time"
2224

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

44-
response := h.Schema.Exec(r.Context(), params.Query, params.OperationName, params.Variables)
46+
ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
47+
defer cancel()
48+
49+
response := h.Schema.Exec(ctx, params.Query, params.OperationName, params.Variables)
4550
responseJSON, err := json.Marshal(response)
4651
if err != nil {
4752
http.Error(w, err.Error(), http.StatusInternalServerError)

0 commit comments

Comments
 (0)