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

build fails with panic if nogo is enabled with nilness static analyzer #2480

Closed
dududko opened this issue May 8, 2020 · 2 comments · Fixed by #2484
Closed

build fails with panic if nogo is enabled with nilness static analyzer #2480

dududko opened this issue May 8, 2020 · 2 comments · Fixed by #2484

Comments

@dududko
Copy link
Contributor

dududko commented May 8, 2020

What version of rules_go are you using?

v0.21.3

What version of gazelle are you using?

v0.20.0

What version of Bazel are you using?

1.2.1

Does this issue reproduce with the latest releases of all the above?

yes

What operating system and processor architecture are you using?

Darwin amd64

What did you do?

git clone https://github.com/dududko/nogo-panic-example
cd ./nogo-panic-example
git checkout a248630ab89bf91b89a67cc177d8f52c6a3d53df
bazel build //:go_default_library

or more specifially

./bazel build @com_github_getkin_kin_openapi//openapi3:go_default_test

What did you expect to see?

Build completed successfully

What did you see instead?

ERROR: /private/var/tmp/_bazel_dududko/08408f84e43117244a5b131913a3fc8a/external/com_github_getkin_kin_openapi/openapi3/BUILD.bazel:3:1: GoCompilePkg external/com_github_getkin_kin_openapi/openapi3/darwin_amd64_stripped/go_default_library%/github.com/getkin/kin-openapi/openapi3.a failed (Exit 1) builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src external/com_github_getkin_kin_openapi/openapi3/callback.go -src ... (remaining 75 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
compilepkg: panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x127cea5]

goroutine 1 [running]:
go/token.(*File).Name(...)
	GOROOT/src/go/token/position.go:110
main.checkAnalysisResults(0xc000190068, 0x1, 0x1, 0xc000392320, 0x1d, 0x1e)
	external/io_bazel_rules_go/go/tools/builders/nogo_main.go:389 +0x475
main.checkPackage(0x1562108, 0x1, 0x1, 0xc0001be003, 0x26, 0xc000182870, 0xc0001828a0, 0xc0001827e0, 0xc0001b05a0, 0x1d, ...)
	external/io_bazel_rules_go/go/tools/builders/nogo_main.go:192 +0x3f0
main.run(0xc0001b0500, 0x27, 0x28, 0x0, 0x0)
	external/io_bazel_rules_go/go/tools/builders/nogo_main.go:84 +0x47c
main.main()
	external/io_bazel_rules_go/go/tools/builders/nogo_main.go:57 +0xa6
Target //:go_default_library failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /Users/dududko/Projects/src/github.com/dududko/nogo-panic-example/BUILD.bazel:4:1 GoCompilePkg external/com_github_getkin_kin_openapi/openapi3/darwin_amd64_stripped/go_default_library%/github.com/getkin/kin-openapi/openapi3.a failed (Exit 1) builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src external/com_github_getkin_kin_openapi/openapi3/callback.go -src ... (remaining 75 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
INFO: Elapsed time: 0.735s, Critical Path: 0.56s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
@dududko
Copy link
Contributor Author

dududko commented May 8, 2020

I added logging to nogo and found out that nilness detects some impossible condition, however the file in which the issue was found is not included in the fileset.

impossible condition: non-nil == nil github.com/getkin/kin-openapi/openapi3

Then I tried to figure out, which file contains the issue. I compiled the static analyzer which only includes nilness.

package main

import (
	"golang.org/x/tools/go/analysis/multichecker"
	"golang.org/x/tools/go/analysis/passes/nilness"
)

func main() {
	multichecker.Main(
		nilness.Analyzer,
	)
}

A executed this binary agains the the openapi3 package https://github.com/getkin/kin-openapi/tree/v0.8.0/openapi3 and indeed the analyzer finds 2 issues, where one of them does not contain a correct path to the source code.

-: impossible condition: non-nil == nil
~/Projects/com_github_getkin_kin_openapi/openapi3/schema.go:1085:64: tautological condition: non-nil != nil

Looks like the analyzer I am using has a bug, but I don't think that because of this the build should fail with panic.

@jayconrod
Copy link
Contributor

Thanks for reporting. #2484 should fix the panic.

As you've said, the root cause is that nilness checker isn't reporting a position for this error. I believe the upstream issue for that is golang/go#31008.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants