Repository: go
Issue: cmd/go: test -coverprofile option causes test to panic
Labels: NeedsInvestigation

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.14.4 linux/amd64
</pre>

Also test with 1.14.9 and 1.15.2, all fail.

### Does this issue reproduce with the latest release?

Yep.

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/go/src/github.com/kubeedge/kubedge/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build657190380=/tmp/go-build -gno-record-gcc-switches"

</pre></details>

### What did you do?

To get coverfile, i add option for `go test`, then go test failed:
```
root@70bbf38bedaf:/go/src/github.com/kubeedge/kubedge# git show
commit 791d503c74b9cdfe2c43a54ad3286fe12ff10d1e (HEAD -> master, origin/master, origin/HEAD)
Author: Xiang Dai <long0dai@foxmail.com>
Date:   Fri Sep 11 16:07:09 2020 +0800

    Generate coverprofile when test

    Signed-off-by: Xiang Dai <long0dai@foxmail.com>

diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
index 14d530a9..d8bcc57d 100644
--- a/hack/lib/golang.sh
+++ b/hack/lib/golang.sh
@@ -434,5 +434,5 @@ kubeedge::golang::run_test() {
     testdirs+=("${KUBEEDGE_ALL_TESTCASES[@]}")
   fi

-  go test ${testdirs[@]}
+  go test -coverprofile=coverprofile.cov ${testdirs[@]}
 }
root@70bbf38bedaf:/go/src/github.com/kubeedge/kubedge# make test
hack/make-rules/clean.sh
hack/make-rules/test.sh
running tests cases
ok  	github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/common/model	0.009s	coverage: 96.3% of statements
ok  	github.com/kubeedge/kubeedge/cloud/pkg/edgecontroller/manager	0.027s	coverage: 26.4% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin	0.019s	coverage: 82.2% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dttype	0.027s	coverage: 95.4% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtmodule	0.019s	coverage: 55.6% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtclient	0.028s	coverage: 96.1% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtcontext	0.013s	coverage: 93.8% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtmanager	51.048s	coverage: 85.6% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtcommon	0.014s	coverage: 100.0% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/metamanager/dao	0.011s	coverage: 100.0% of statements
PASS
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0xb75749]

goroutine 12 [running]:
github.com/kubeedge/kubeedge/edge/pkg/metamanager/dao.QueryAllMeta(0xd6e86a, 0x4, 0xd70d24, 0x9, 0x0, 0x0, 0x0)
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/dao/meta.go:97 +0x49
github.com/kubeedge/kubeedge/edge/pkg/metamanager.(*metaManager).syncPodStatus(0xc00003d418)
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/process.go:516 +0xa9
github.com/kubeedge/kubeedge/edge/pkg/metamanager.(*metaManager).processSync(...)
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/process.go:511
github.com/kubeedge/kubeedge/edge/pkg/metamanager.(*metaManager).process(0xc00003d418, 0xc000040e40, 0x24, 0x0, 0x0, 0x17499ee0ec9, 0x0, 0x0, 0x0, 0xd722e4, ...)
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/process.go:646 +0x50b
github.com/kubeedge/kubeedge/edge/pkg/metamanager.(*metaManager).runMetaManager.func1(0xc00003d418)
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/process.go:670 +0x318
created by github.com/kubeedge/kubeedge/edge/pkg/metamanager.(*metaManager).runMetaManager
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/process.go:660 +0x49
FAIL	github.com/kubeedge/kubeedge/edge/pkg/metamanager	0.009s
ok  	github.com/kubeedge/kubeedge/edge/pkg/servicebus/util	0.021s	coverage: 60.6% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/eventbus/common/util	0.019s	coverage: 65.9% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/edgehub/clients/wsclient	0.190s	coverage: 3.0% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/edgehub/common/http	0.071s	coverage: 36.7% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/edgehub	24.017s	coverage: 60.6% of statements
ok  	github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/util	0.010s	coverage: 1.1% of statements
FAIL
make: *** [Makefile:91: test] Error 1
```

Reproduce:
```
$ docker run -it golang:1.14 bash
$ go get github.com/daixiang0/kubeedge
$ cd /go/src/github.com/daixiang0/kubeedge
$ make test
```


### What did you expect to see?

Test pass.


### What did you see instead?

Test failed.

If revert this change, test pass.

I check docs while do not get any helpful info :(