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

cmd/go: unexpected panic when running go test on particular package without test files #25789

Closed
mark-rushakoff opened this issue Jun 7, 2018 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mark-rushakoff
Copy link
Contributor

What version of Go are you using (go version)?

gotip version
go version devel +7b08e619bb Thu Jun 7 16:17:04 2018 +0000 darwin/amd64

Does this issue reproduce with the latest release?

I tested with go1.10.1 and it does not reproduce.

What operating system and processor architecture are you using (go env)?

$ gotip env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mr/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mr/go"
GORACE=""
GOROOT="/Users/mr/gotip/src/github.com/golang/go"
GOTMPDIR=""
GOTOOLDIR="/Users/mr/gotip/src/github.com/golang/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ct/bl4_z3g51ks8239_r2k07v_40000gn/T/go-build990290390=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I created a repository that you can clone to reproduce this issue: https://github.com/mark-rushakoff/testpanic

I am sure the repro case could be stripped down quite a bit, but I do not have time to minimize it any further right now.

That repository's main.go contains only the following code:

package main

import (
	"net/http"

	"github.com/elazarl/goproxy"
	"github.com/sirupsen/logrus"
)

func main() {
	proxy := goproxy.NewProxyHttpServer()
	proxy.Verbose = true
	logrus.Fatal(http.ListenAndServe(":8080", proxy))
}

Then I ran go test .

What did you expect to see?

I expected to see the same output that I see in go 1.10:

go test .
?       github.com/mark-rushakoff/testpanic     [no test files]

What did you see instead?

I saw a panic from an init function, that I would not have expected to run on account of there being no test files:

$ GOTRACEBACK=system gotip test .
panic: Error parsing builtin CA x509: RSA key missing NULL parameters

goroutine 1 [running]:
panic(0x1271080, 0xc000049060)
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/panic.go:537 +0x2cb fp=0xc000115df0 sp=0xc000115d60 pc=0x102cbfb
github.com/mark-rushakoff/testpanic/vendor/github.com/elazarl/goproxy.init.0()
        /Users/mr/go/src/github.com/mark-rushakoff/testpanic/vendor/github.com/elazarl/goproxy/certs.go:10 +0x1bc fp=0xc000115e58 sp=0xc000115df0 pc=0x1240b0c
github.com/mark-rushakoff/testpanic/vendor/github.com/elazarl/goproxy.init()
        <autogenerated>:1 +0x250 fp=0xc000115f78 sp=0xc000115e58 pc=0x1240d70
github.com/mark-rushakoff/testpanic.init()
        <autogenerated>:1 +0x4a fp=0xc000115f88 sp=0xc000115f78 pc=0x1243faa
main.init()
        <autogenerated>:1 +0x54 fp=0xc000115f98 sp=0xc000115f88 pc=0x1244254
runtime.main()
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/proc.go:189 +0x1bd fp=0xc000115fe0 sp=0xc000115f98 pc=0x102e8ad
runtime.goexit()
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc000115fe8 sp=0xc000115fe0 pc=0x105b941

goroutine 2 [force gc (idle)]:
runtime.gopark(0x12eb408, 0x14ea090, 0x1410, 0x1)
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/proc.go:298 +0xeb fp=0xc000032f80 sp=0xc000032f60 pc=0x102eceb
runtime.goparkunlock(0x14ea090, 0x1410, 0x1)
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/proc.go:304 +0x53 fp=0xc000032fb0 sp=0xc000032f80 pc=0x102ed93
runtime.forcegchelper()
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/proc.go:251 +0xb3 fp=0xc000032fe0 sp=0xc000032fb0 pc=0x102eb63
runtime.goexit()
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc000032fe8 sp=0xc000032fe0 pc=0x105b941
created by runtime.init.4
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/proc.go:240 +0x35

goroutine 3 [GC sweep wait]:
runtime.gopark(0x12eb408, 0x14ea1e0, 0x102140c, 0x1)
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/proc.go:298 +0xeb fp=0xc000033780 sp=0xc000033760 pc=0x102eceb
runtime.goparkunlock(0x14ea1e0, 0x131140c, 0x1)
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/proc.go:304 +0x53 fp=0xc0000337b0 sp=0xc000033780 pc=0x102ed93
runtime.bgsweep(0xc00006a000)
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/mgcsweep.go:52 +0x8f fp=0xc0000337d8 sp=0xc0000337b0 pc=0x1020b5f
runtime.goexit()
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc0000337e0 sp=0xc0000337d8 pc=0x105b941
created by runtime.gcenable
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/mgc.go:216 +0x58

goroutine 4 [finalizer wait]:
runtime.gopark(0x12eb408, 0x1507da0, 0x129140f, 0x1)
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/proc.go:298 +0xeb fp=0xc000032728 sp=0xc000032708 pc=0x102eceb
runtime.goparkunlock(0x1507da0, 0x140f, 0x1)
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/proc.go:304 +0x53 fp=0xc000032758 sp=0xc000032728 pc=0x102ed93
runtime.runfinq()
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/mfinal.go:175 +0x99 fp=0xc0000327e0 sp=0xc000032758 pc=0x10185b9
runtime.goexit()
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc0000327e8 sp=0xc0000327e0 pc=0x105b941
created by runtime.createfing
        /Users/mr/gotip/src/github.com/golang/go/src/runtime/mfinal.go:156 +0x61
FAIL    github.com/mark-rushakoff/testpanic     0.017s
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 7, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Jun 7, 2018
@ianlancetaylor ianlancetaylor changed the title test: unexpected panic when running go test on particular package without test files cmd/go: unexpected panic when running go test on particular package without test files Jun 7, 2018
@ianlancetaylor
Copy link
Contributor

The go tool does now build and run the test binary even if there aren't any tests. If this didn't happen in 1.10, it happens on tip most likely because of #24570. It does seem simpler to handle things consistently, rather than having a special case when there are no tests.

JeremyRand added a commit to JeremyRand/tlsrestrictnss that referenced this issue Jun 18, 2018
Go 1.11 and higher execute the init() function when tests are run, even if no tests exist in the package.  This caused problems since tlsrestrict_nss_tool's init() function produces errors when options aren't explicitly provided by the user via command-line flags or a config file.  See golang/go#25789 for more info.  This commit moves that code from init() to main().
JeremyRand added a commit to namecoin/tlsrestrictnss that referenced this issue Jun 20, 2018
5c5bee4 Fix test failures on Go 1.11 and higher. (JeremyRand)

Pull request description:

  Go 1.11 and higher execute the `init()` function when tests are run, even if no tests exist in the package.  This caused problems since `tlsrestrict_nss_tool`'s `init()` function produces errors when options aren't explicitly provided by the user via command-line flags or a config file.  See golang/go#25789 for more info.  This commit moves that code from `init()` to `main()`.

Tree-SHA512: 27eed58a85a5dba26669a4f3f8dd337a966e5020a86f0d3fdc773fc1db3b56d056b1011bb92b552507440da2932500d0fae54ca7abe03bca555567f1f801fca0
@rsc
Copy link
Contributor

rsc commented Jul 6, 2018

Duplicate (now) of #26242, which we will fix for Go 1.11.

@rsc rsc closed this as completed Jul 6, 2018
@gopherbot
Copy link

Change https://golang.org/cl/122518 mentions this issue: cmd/go: revert "output coverage report even if there are no test files"

gopherbot pushed a commit that referenced this issue Jul 9, 2018
Original CL description:

    When using test -cover or -coverprofile the output for "no test files"
    is the same format as for "no tests to run".

Reverting because this CL changed cmd/go to build test binaries for
packages that have no tests, leading to extra work and confusion.

Updates #24570
Fixes #25789
Fixes #26157
Fixes #26242

Change-Id: Ibab1307d39dfaec0de9359d6d96706e3910c8efd
Reviewed-on: https://go-review.googlesource.com/122518
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
@golang golang locked and limited conversation to collaborators Jul 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants