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

fix(GraphQL): Fix segmentation fault when calling the /admin/backup endpoint. #6042

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions dgraph/cmd/alpha/admin_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/dgraph-io/dgraph/graphql/web"

"github.com/dgraph-io/dgraph/x"
"github.com/golang/glog"
)

func init() {
Expand Down Expand Up @@ -55,6 +56,7 @@ func backupHandler(w http.ResponseWriter, r *http.Request, adminServer web.IServ
"forceFull": r.FormValue("force_full") == "true",
}},
}
glog.Infof("gqlReq %+v, r %+v adminServer %+v", gqlReq, r, adminServer)
resp := resolveWithAdminServer(gqlReq, r, adminServer)
if resp.Errors != nil {
x.SetStatus(w, resp.Errors.Error(), "Backup failed.")
Expand Down
5 changes: 4 additions & 1 deletion dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,10 @@ func setupServer(closer *y.Closer) {
// The global epoch is set to maxUint64 while exiting the server.
// By using this information polling goroutine terminates the subscription.
globalEpoch := uint64(0)
mainServer, adminServer, gqlHealthStore := admin.NewServers(introspection, &globalEpoch, closer)
var mainServer web.IServeGraphQL
var gqlHealthStore *admin.GraphQLHealthStore
// Do not use := notation here because adminServer is a global variable.
mainServer, adminServer, gqlHealthStore = admin.NewServers(introspection, &globalEpoch, closer)
http.Handle("/graphql", mainServer.HTTPHandler())
http.HandleFunc("/probe/graphql", func(w http.ResponseWriter, r *http.Request) {
healthStatus := gqlHealthStore.GetHealth()
Expand Down
28 changes: 6 additions & 22 deletions systest/backup/minio-large/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
package main

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"math"
"net/http"
"net/url"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -141,26 +140,11 @@ func addTriples(t *testing.T, dg *dgo.Dgraph, numTriples int) {
}

func runBackup(t *testing.T) {
backupRequest := `mutation backup($dst: String!) {
backup(input: {destination: $dst}) {
response {
code
message
}
}
}`

adminUrl := "http://localhost:8180/admin"
params := testutil.GraphQLParams{
Query: backupRequest,
Variables: map[string]interface{}{
"dst": backupDestination,
},
}
b, err := json.Marshal(params)
require.NoError(t, err)

resp, err := http.Post(adminUrl, "application/json", bytes.NewBuffer(b))
// Using the old /admin/backup endpoint to ensure it works. Change back to using
// the GraphQL endpoint at /admin once this endpoint is deprecated.
resp, err := http.PostForm("http://localhost:8180/admin/backup", url.Values{
"destination": []string{backupDestination},
})
require.NoError(t, err)
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
Expand Down