Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(graphql): fixing query timeouts for graphql queries too #7796

Merged
merged 2 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this comments is still valid. Please check and suggest should I fix this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is still valid.

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