Skip to content

Commit

Permalink
fix(GraphQL): Fix segmentation fault when calling the /admin/backup e…
Browse files Browse the repository at this point in the history
…ndpoint. (#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 6d01404)
  • Loading branch information
martinmr authored Jul 20, 2020
1 parent bc07dca commit d6c58a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
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 @@ -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()
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

0 comments on commit d6c58a7

Please sign in to comment.