From d6c58a7d5b61cfe6f17698e2a12e15a232553fff Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Mon, 20 Jul 2020 14:47:55 -0700 Subject: [PATCH] fix(GraphQL): Fix segmentation fault when calling the /admin/backup endpoint. (#6042) (#6043) PR #5802 introduced a bug that caused the adminServer global variable to never be set, which in turned caused a segmentation fault when the /admin/backup endpoint was called. This PR fixes the bug and changes the minio-large test to use the /admin/backup endpoint to act as a regression test. Fixes DGRAPH-1938. (cherry picked from commit 6d014042730fd65bbaec66b7a6d0a4c93a9b58f2) --- dgraph/cmd/alpha/admin_backup.go | 2 ++ dgraph/cmd/alpha/run.go | 5 +++- systest/backup/minio-large/backup_test.go | 28 +++++------------------ 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/dgraph/cmd/alpha/admin_backup.go b/dgraph/cmd/alpha/admin_backup.go index 9644b519d28..8a49d5278f3 100644 --- a/dgraph/cmd/alpha/admin_backup.go +++ b/dgraph/cmd/alpha/admin_backup.go @@ -26,6 +26,7 @@ import ( "github.com/dgraph-io/dgraph/graphql/web" "github.com/dgraph-io/dgraph/x" + "github.com/golang/glog" ) func init() { @@ -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.") diff --git a/dgraph/cmd/alpha/run.go b/dgraph/cmd/alpha/run.go index 23a5cb31828..f9ad420b2be 100644 --- a/dgraph/cmd/alpha/run.go +++ b/dgraph/cmd/alpha/run.go @@ -470,7 +470,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() diff --git a/systest/backup/minio-large/backup_test.go b/systest/backup/minio-large/backup_test.go index ab5478763b1..0df2a2f44b8 100644 --- a/systest/backup/minio-large/backup_test.go +++ b/systest/backup/minio-large/backup_test.go @@ -16,13 +16,12 @@ package main import ( - "bytes" "context" - "encoding/json" "fmt" "io/ioutil" "math" "net/http" + "net/url" "os" "strings" "testing" @@ -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)