Skip to content

Commit

Permalink
cherry-pick: chore(graphql): fixing query timeouts for graphql querie…
Browse files Browse the repository at this point in the history
…s too (#7796)

- fixing query timeouts for GraphQL queries too
- fixing online restore test

(cherry picked from commit bb0358e)
  • Loading branch information
ahsanbarkati committed Jun 2, 2021
2 parents 25c9d92 + d4770b2 commit 3868e8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 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 @@ -1256,6 +1256,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 @@ -1294,8 +1304,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

0 comments on commit 3868e8f

Please sign in to comment.