Skip to content

Commit

Permalink
chore(graphql): fixing query timeouts for graphql queries too (#7796)
Browse files Browse the repository at this point in the history
* fixing query timeouts for graphql queries too

* fixing online restore test
  • Loading branch information
aman-bansal authored May 10, 2021
1 parent 68b42cf commit bb0358e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
13 changes: 11 additions & 2 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
}
Expand Down Expand Up @@ -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()
}
Expand Down
5 changes: 0 additions & 5 deletions systest/online-restore/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bb0358e

Please sign in to comment.