From bb0358e6db5e0731023af4d7a1163d1227959133 Mon Sep 17 00:00:00 2001 From: aman bansal Date: Mon, 10 May 2021 12:25:01 +0530 Subject: [PATCH] chore(graphql): fixing query timeouts for graphql queries too (#7796) * fixing query timeouts for graphql queries too * fixing online restore test --- dgraph/cmd/alpha/run.go | 2 +- edgraph/server.go | 13 +++++++++++-- systest/online-restore/docker-compose.yml | 5 ----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dgraph/cmd/alpha/run.go b/dgraph/cmd/alpha/run.go index 717c0988530..b1dd1b68cf0 100644 --- a/dgraph/cmd/alpha/run.go +++ b/dgraph/cmd/alpha/run.go @@ -207,7 +207,7 @@ they form a Raft group and provide synchronous replication. Flag("txn-abort-after", "Abort any pending transactions older than this duration."+ " The liveness of a transaction is determined by its last mutation."). Flag("shared-instance", "When set to true, it disables ACLs for non-galaxy users. "+ - "It expects the access JWT to be contructed outside dgraph for those users as even "+ + "It expects the access JWT to be constructed outside dgraph for those users as even "+ "login is denied to them. Additionally, this disables access to environment variables"+ "for minio, aws, etc."). String()) diff --git a/edgraph/server.go b/edgraph/server.go index df1afeca94d..e2d33c4e3b4 100644 --- a/edgraph/server.go +++ b/edgraph/server.go @@ -1102,6 +1102,16 @@ func getAuthMode(ctx context.Context) AuthMode { // QueryGraphQL handles only GraphQL queries, neither mutations nor DQL. func (s *Server) QueryGraphQL(ctx context.Context, req *api.Request, field gqlSchema.Field) (*api.Response, error) { + // Add a timeout for queries which don't have a deadline set. We don't want to + // apply a timeout if it's a mutation, that's currently handled by flag + // "txn-abort-after". + if req.GetMutations() == nil && x.Config.QueryTimeout != 0 { + if d, _ := ctx.Deadline(); d.IsZero() { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, x.Config.QueryTimeout) + defer cancel() + } + } // no need to attach namespace here, it is already done by GraphQL layer return s.doQuery(ctx, &Request{req: req, gqlField: field, doAuth: getAuthMode(ctx)}) } @@ -1140,8 +1150,7 @@ func Init() { maxPendingQueries = x.Config.Limit.GetInt64("max-pending-queries") } -func (s *Server) doQuery(ctx context.Context, req *Request) ( - resp *api.Response, rerr error) { +func (s *Server) doQuery(ctx context.Context, req *Request) (resp *api.Response, rerr error) { if ctx.Err() != nil { return nil, ctx.Err() } diff --git a/systest/online-restore/docker-compose.yml b/systest/online-restore/docker-compose.yml index e0880d479c3..5fb4c7614e0 100644 --- a/systest/online-restore/docker-compose.yml +++ b/systest/online-restore/docker-compose.yml @@ -208,11 +208,6 @@ services: --logtostderr -v=2 --raft "idx=6;" --encryption "key-file=/data/keys/enc_key;" --security "whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;" --tls "ca-cert=/dgraph-tls/ca.crt; server-cert=/dgraph-tls/node.crt; server-key=/dgraph-tls/node.key; internal-port=true; client-cert=/dgraph-tls/client.alpha6.crt; client-key=/dgraph-tls/client.alpha6.key;" - ratel: - image: dgraph/dgraph:latest - ports: - - 8000 - command: dgraph-ratel zero1: image: dgraph/dgraph:latest working_dir: /data/zero1