Skip to content
Snippets Groups Projects
Closed graphql api: panic when trying to lookup contents of file matches returned by zoekt
  • View options
  • graphql api: panic when trying to lookup contents of file matches returned by zoekt

  • View options
  • Closed Issue created by Warren Gifford

    Created by: ggilmore

    Steps to reproduce:

    1. Start the dev server with indexed search enabled:

      INDEXED_SEARCH=1 ./enterprise/dev/start.sh
    2. Add http://github.com/gorilla/mux to your instance

    3. Go the GraphQL API console (http://localhost:3080/api/console#%7B%22variables%22%3A%22%7B%5Cn%20%20%5C%22query%5C%22%3A%20%5C%22repo%3Agorilla%2Fmux%20travis%20count%3A1%5C%22%5Cn%7D%22%7D) and run the following:

      query Search($query: String) {
        search(query: $query) {
          results {
            results {
              ... on FileMatch {
                file {
                  commit {
                    oid
                  }
                  path
                  content
                }
              }
            }
          }
        }
      }
      
      # Query Variables
      {
        "query": "repo:gorilla/mux travis count:1"
      }

    Expected behavior:

    The results succesfully return with the requested file contents:

    {
      "data": {
        "search": {
          "results": {
            "results": [
              {
                "file": {
                  "commit": {
                    "oid": "a7962380ca08b5a188038c69871b8d3fbdf31e89"
                  },
                  "path": ".travis.yml",
                  "content": "language: go\nsudo: false\n\nmatrix:\n  include:\n    - go: 1.7.x\n    - go: 1.8.x\n    - go: 1.9.x\n    - go: 1.10.x\n    - go: 1.11.x\n    - go: 1.x\n      env: LATEST=true\n    - go: tip\n  allow_failures:\n    - go: tip\n\ninstall:\n  - # Skip\n\nscript:\n  - go get -t -v ./...\n  - diff -u <(echo -n) <(gofmt -d .)\n  - if [[ \"$LATEST\" = true ]]; then go tool vet .; fi\n  - go test -v -race ./...\n"
                }
              }
            ]
          }
        }
      }
    }

    Actual behavior:

    The results have null contents and contain errors:

    {
      "data": {
        "search": {
          "results": {
            "results": [
              {
                "file": {
                  "commit": {
                    "oid": ""
                  },
                  "path": ".travis.yml",
                  "content": null
                }
              }
            ]
          }
        }
      },
      "errors": [
        {
          "message": "graphql: panic occurred: non-absolute commit ID: \"\"",
          "path": [
            "search",
            "results",
            "results",
            0,
            "file",
            "content"
          ]
        }
      ]
    }

    Also see these logs:

    13:50:57               frontend | graphql: panic occurred: non-absolute commit ID: ""
    13:50:57               frontend | goroutine 28043 [running]:
    13:50:57               frontend | github.com/graph-gophers/graphql-go/log.(*DefaultLogger).LogPanic(0x30083f0, 0x23bd740, 0xc0006220f0, 0x1f79ce0, 0xc00080aa70)
    13:50:57               frontend | 	/Users/ggilmore/dev/go/pkg/mod/github.com/sourcegraph/graphql-go@v0.0.0-20180929065141-c790ffc3c46a/log/log.go:21 +0x77
    13:50:57               frontend | github.com/graph-gophers/graphql-go/internal/exec.execFieldSelection.func2.1(0xc00062a240, 0x23bd740, 0xc0006220f0, 0xc00121def8, 0xc000485760)
    13:50:57               frontend | 	/Users/ggilmore/dev/go/pkg/mod/github.com/sourcegraph/graphql-go@v0.0.0-20180929065141-c790ffc3c46a/internal/exec/exec.go:161 +0x87
    13:50:57               frontend | panic(0x1f79ce0, 0xc00080aa70)
    13:50:57               frontend | 	/usr/local/Cellar/go/1.11.5/libexec/src/runtime/panic.go:513 +0x1b9
    13:50:57               frontend | github.com/sourcegraph/sourcegraph/pkg/vcs/git.ensureAbsCommit(0x0, 0x0)
    13:50:57               frontend | 	/Users/ggilmore/dev/go/src/github.com/sourcegraph/sourcegraph/pkg/vcs/git/revisions.go:38 +0xed
    13:50:57               frontend | github.com/sourcegraph/sourcegraph/pkg/vcs/git.readFileBytes(0x23bd740, 0xc0006435f0, 0xc000654620, 0x16, 0x0, 0x0, 0x0, 0x0, 0xc000c9ab50, 0xd, ...)
    13:50:57               frontend | 	/Users/ggilmore/dev/go/src/github.com/sourcegraph/sourcegraph/pkg/vcs/git/blob.go:35 +0x50
    13:50:57               frontend | github.com/sourcegraph/sourcegraph/pkg/vcs/git.ReadFile(0x23bd740, 0xc0006435f0, 0xc000654620, 0x16, 0x0, 0x0, 0x0, 0x0, 0xc000c9ab50, 0xd, ...)
    13:50:57               frontend | 	/Users/ggilmore/dev/go/src/github.com/sourcegraph/sourcegraph/pkg/vcs/git/blob.go:27 +0x24d
    13:50:57               frontend | github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend.(*gitTreeEntryResolver).Content(0xc000622240, 0x23bd700, 0xc0006009c0, 0x0, 0x0, 0x0, 0x0)
    13:50:57               frontend | 	/Users/ggilmore/dev/go/src/github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/file.go:26 +0x158
    13:50:57               frontend | reflect.Value.call(0x2182600, 0xc0006114a8, 0x1293, 0x21b6de0, 0x4, 0xc000485800, 0x1, 0x1, 0x2182600, 0x17, ...)
    13:50:57               frontend | 	/usr/local/Cellar/go/1.11.5/libexec/src/reflect/value.go:447 +0x454
    13:50:57               frontend | reflect.Value.Call(0x2182600, 0xc0006114a8, 0x1293, 0xc000485800, 0x1, 0x1, 0x1293, 0x1, 0xbe073701fa)
    13:50:57               frontend | 	/usr/local/Cellar/go/1.11.5/libexec/src/reflect/value.go:308 +0xa4
    13:50:57               frontend | github.com/graph-gophers/graphql-go/internal/exec.execFieldSelection.func2(0xc00062a240, 0x23bd740, 0xc0006220f0, 0xc000485760, 0xc0016bfbc0, 0xc00121df40, 0x23bd740, 0xc0006222a0, 0x0)
    13:50:57               frontend | 	/Users/ggilmore/dev/go/pkg/mod/github.com/sourcegraph/graphql-go@v0.0.0-20180929065141-c790ffc3c46a/internal/exec/exec.go:183 +0x3b9
    13:50:57               frontend | github.com/graph-gophers/graphql-go/internal/exec.execFieldSelection(0x23bd740, 0xc0006220f0, 0xc00062a240, 0xc0016bfbc0, 0xc000485760, 0xc000642801)
    13:50:57               frontend | 	/Users/ggilmore/dev/go/pkg/mod/github.com/sourcegraph/graphql-go@v0.0.0-20180929065141-c790ffc3c46a/internal/exec/exec.go:193 +0x1aa
    13:50:57               frontend | github.com/graph-gophers/graphql-go/internal/exec.(*Request).execSelections.func1(0xc000c9acd0, 0xc00062a240, 0x23bd740, 0xc0006220f0, 0xc000485640, 0xc0016bfbc0)
    13:50:57               frontend | 	/Users/ggilmore/dev/go/pkg/mod/github.com/sourcegraph/graphql-go@v0.0.0-20180929065141-c790ffc3c46a/internal/exec/exec.go:74 +0x161
    13:50:57               frontend | created by github.com/graph-gophers/graphql-go/internal/exec.(*Request).execSelections
    13:50:57               frontend | 	/Users/ggilmore/dev/go/pkg/mod/github.com/sourcegraph/graphql-go@v0.0.0-20180929065141-c790ffc3c46a/internal/exec/exec.go:70 +0x478

    The GraphQL results sucessfully return if you disable indexed search by adding index:no to your search query:

    Query:

    query Search($query: String) {
      search(query: $query) {
        results {
          results {
            ... on FileMatch {
              file {
                commit {
                  oid
                }
                path
                content
              }
            }
          }
        }
      }
    }
    
    # Query Variables
    {
      "query": "repo:gorilla/mux index:no travis count:1"
    }

    Results:

    {
      "data": {
        "search": {
          "results": {
            "results": [
              {
                "file": {
                  "commit": {
                    "oid": "a7962380ca08b5a188038c69871b8d3fbdf31e89"
                  },
                  "path": ".travis.yml",
                  "content": "language: go\nsudo: false\n\nmatrix:\n  include:\n    - go: 1.7.x\n    - go: 1.8.x\n    - go: 1.9.x\n    - go: 1.10.x\n    - go: 1.11.x\n    - go: 1.x\n      env: LATEST=true\n    - go: tip\n  allow_failures:\n    - go: tip\n\ninstall:\n  - # Skip\n\nscript:\n  - go get -t -v ./...\n  - diff -u <(echo -n) <(gofmt -d .)\n  - if [[ \"$LATEST\" = true ]]; then go tool vet .; fi\n  - go test -v -race ./...\n"
                }
              }
            ]
          }
        }
      }
    }

    Specifiying a branch in your query e.g. r:gorilla/mux@master also works.

    It seems like the indexed-search code path specifically provides an empty commit field to the fileMatchResolver:

    https://github.com/sourcegraph/sourcegraph/blob/3da30d22b074a6ae2581adca6554a6376401e901/cmd/frontend/graphqlbackend/textsearch.go#L538

    However, this is an issue for the fileMatchResolver's Content() method:

    https://github.com/sourcegraph/sourcegraph/blob/3da30d22b074a6ae2581adca6554a6376401e901/cmd/frontend/graphqlbackend/file.go#L26

    Which panics because the commit that's passed to its methods isn't an absolute one:

    https://github.com/sourcegraph/sourcegraph/blob/3da30d22b074a6ae2581adca6554a6376401e901/pkg/vcs/git/blob.go#L35

    Activity

    • All activity
    • Comments only
    • History only
    • Newest first
    • Oldest first