Closed
Description
What version of Go are you using (go version
)?
go version go1.10.3 linux/amd64
Does this issue reproduce with the latest release?
Yes. We also saw this with 1.10.2.
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jwebb/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jwebb/gocode"
GORACE=""
GOROOT="/home/jwebb/opt/go"
GOTMPDIR=""
GOTOOLDIR="/home/jwebb/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build138291515=/tmp/go-build -gno-record-gcc-switches"
What did you do?
This appears to be triggered by any cyclic import, but only with use of the {{.Stale}}
template, e.g.:
#!/bin/bash
set -ex
export GOPATH="$PWD"
mkdir -p src/testorg/pkg{1,2}
cat > src/testorg/pkg1/pkg1.go <<EOF
package pkg1
import "testorg/pkg2"
EOF
cat > src/testorg/pkg2/pkg2.go <<EOF
package pkg2
import "testorg/pkg1"
EOF
go list -f '{{.Stale}}' testorg/...
What did you expect to see?
An error message about the cyclic import, but no crash.
What did you see instead?
A stack overflow:
can't load package: import cycle not allowed
package testorg/pkg1
imports testorg/pkg2
imports testorg/pkg1
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow
runtime stack:
runtime.throw(0x8af01b, 0xe)
/usr/local/go/src/runtime/panic.go:616 +0x81
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1054 +0x71f
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:480 +0x89
goroutine 1 [running]:
fmt.(*fmt).pad(0xc421a22040, 0xc421a220a5, 0x7, 0x7)
/usr/local/go/src/fmt/format.go:90 +0x3a9 fp=0xc440b16350 sp=0xc440b16348 pc=0x4bff39
fmt.(*fmt).fmt_integer(0xc421a22040, 0x1642c1, 0xa, 0x1, 0x8b0091, 0x11)
/usr/local/go/src/fmt/format.go:307 +0x1db fp=0xc440b163a0 sp=0xc440b16350 pc=0x4c08fb
fmt.(*pp).fmtInteger(0xc421a22000, 0x1642c1, 0x6400000001)
/usr/local/go/src/fmt/print.go:369 +0x1e5 fp=0xc440b163e0 sp=0xc440b163a0 pc=0x4c4105
fmt.(*pp).printArg(0xc421a22000, 0x80f6c0, 0xc4401dd5a8, 0x64)
/usr/local/go/src/fmt/print.go:649 +0x837 fp=0xc440b16458 sp=0xc440b163e0 pc=0x4c6717
fmt.(*pp).doPrintf(0xc421a22000, 0x8aa476, 0x5, 0xc440b165d0, 0x1, 0x1)
/usr/local/go/src/fmt/print.go:1099 +0x3fa fp=0xc440b16540 sp=0xc440b16458 pc=0x4c9ada
fmt.Sprintf(0x8aa476, 0x5, 0xc440b165d0, 0x1, 0x1, 0x20, 0x0)
/usr/local/go/src/fmt/print.go:203 +0x66 fp=0xc440b16598 sp=0xc440b16540 pc=0x4c2c26
cmd/go/internal/work.(*Builder).NewObjdir(0xc420258460, 0x20, 0xc440b166b8)
/usr/local/go/src/cmd/go/internal/work/action.go:257 +0x94 fp=0xc440b16610 sp=0xc440b16598 pc=0x5ea314
cmd/go/internal/work.(*Builder).CompileAction.func1(0x830b00)
/usr/local/go/src/cmd/go/internal/work/action.go:335 +0x53 fp=0xc440b166b8 sp=0xc440b16610 pc=0x621073
cmd/go/internal/work.(*Builder).cacheAction(0xc420258460, 0x8aa494, 0x5, 0xc420086c00, 0xc440b16750, 0x412138)
/usr/local/go/src/cmd/go/internal/work/action.go:300 +0x9f fp=0xc440b16720 sp=0xc440b166b8 pc=0x5eabef
cmd/go/internal/work.(*Builder).CompileAction(0xc420258460, 0x1, 0x1, 0xc420086c00, 0xc43445b1ff)
/usr/local/go/src/cmd/go/internal/work/action.go:330 +0xc0 fp=0xc440b16780 sp=0xc440b16720 pc=0x5eae10
cmd/go/internal/work.(*Builder).CompileAction.func1(0x830b00)
/usr/local/go/src/cmd/go/internal/work/action.go:339 +0x16e fp=0xc440b16828 sp=0xc440b16780 pc=0x62118e
cmd/go/internal/work.(*Builder).cacheAction(0xc420258460, 0x8aa494, 0x5, 0xc420086800, 0xc440b168c0, 0x412138)
/usr/local/go/src/cmd/go/internal/work/action.go:300 +0x9f fp=0xc440b16890 sp=0xc440b16828 pc=0x5eabef
etc.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
[-]"go list -f '{{.Stale}}'" stack overflow with cyclic imports[/-][+]cmd/go: "go list -f '{{.Stale}}'" stack overflow with cyclic imports[/+]iwdgo commentedon Apr 21, 2019
This issue cannot be reproduced on go1.12.2.
The description above is placing files in
$GOPATH/src/src
but this is not creating an issue either assrc
is appended to GOPATH. Issue seems solved.bcmills commentedon Feb 4, 2021
We got a report via Slack of what seems to be the same crash on Go 1.15.7, with the following cycle in the stack trace:
go/src/cmd/go/internal/work/action.go
Line 371 in e8e7fac
go/src/cmd/go/internal/work/action.go
Line 404 in e8e7fac
go/src/cmd/go/internal/work/action.go
Line 414 in e8e7fac
Like the original report — and like #43279 — the top of the stack at the time of the crash was in the
fmt
package via(*Builder).NewObjdir
. It seems that this bug is still present.bcmills commentedon Feb 4, 2021
I'm intrigued by the condition that is supposed to guard against import cycles here:
go/src/cmd/go/internal/work/action.go
Line 412 in e8e7fac
Perhaps
p.Error
is starting out as animport cycle
error, butt somehow being overwritten with some error for whichp.Error.IsImportCycle
is false?CC @jayconrod @matloob
rolandshoemaker commentedon Mar 12, 2021
I ran into this when analyzing some gVisor code. In particular the package
gvisor.dev/gvisor/pkg/sync
will trigger the issue. It appears to be caused by two packages being defined in the same directory (heresync
andseqatomic
), causingp.Error
to be populated with aMultiplePackageError
, while also containing an import loop (seqatomic
importssync
).Because
p.Error != nil
andp.Error.IsImportCycle != true
we get stuck in theCompileAction
loop. This is obviously a very weird situation, and I'm honestly not really sure what the correct solution is. It seems like probablyreusePackage
should either be settingIsImportCycle
when it detects a loop, andp.Error
is already set, or it should stomp the existingp.Error
and overwrite with the import loop error, since that is likely to be the more useful error, but my familiarity with this area of the codebase is pretty limited, so there might be a good reason not to do that.jayconrod commentedon Mar 12, 2021
Reproduced at
gvisor.dev/gvisor@ab488702a
by runninggo list -compiled -e
.Thank you!
21 remaining items