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

Error when logging a map using Printf with %v #33800

Closed
rcostu opened this issue Aug 23, 2019 · 3 comments

Comments

@rcostu
Copy link

commented Aug 23, 2019

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

$ go version
go version go1.12.7 darwin/amd64

Does this issue reproduce with the latest release?

Don't know. Problem is sparse and difficult to replicate.

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

go env Output
$ go env
GOARCH="amd64"
GOBIN="/usr/local/bin"
GOCACHE="/Users/rcostumero/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/rcostumero/src/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/2m/zj05vmjx51bgpjc16bs17yzm0000gn/T/go-build323529105=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Unfortunately I haven't been able to reproduce the failure in a smaller piece of code that I can share (working for a private project). Error is sparse and only reproduces ocassionally.

The program has several goroutines running in parallel and communicated with a centralized goroutine that operates as a name service and shares information with each goroutine. Each goroutine registers into the NS, the NS updates the list of registered goroutines, and shares the list after registration with all the goroutines for updating the registry (a copy, not a pointer to it).

The goroutine after receiving the confirmation, uses the log package to show that the updated list is received.

The last line of code failing in my program is:

log.Printf("%v", ag.agentList)

where:
ag is an struct with several fields
agentList is of type map[string]chan<- *Message
and Message is an struct containing several strings.

What did you expect to see?

2019/08/23 14:20:14 map[Agente0:0xc00008a180 Agente1:0xc00008e180 Agente2:0xc00005c060 Agente3:0xc00005c120 Agente4:0xc00008e240 Agente5:0xc000108240 Agente6:0xc000148060 Agente7:0xc00005c360 Agente8:0xc00014a0c0 Agente9:0xc00005c420]

What did you see instead?

map[Agente0:0xc00008a180 Agente1:0xc00008e180 Agente2:0xc00005c060 Agente3:0xc00005c120 Agente4:0xc00008e240 Agente5:0xc000108240 Agente6:0xc000148060 Agente7:0xc00005c360 Agente8:0xc00014a0c0 Agente9:0xc00005c420]
panic: runtime error: index out of range

goroutine 5 [running]:
internal/fmtsort.Sort(0x10b44a0, 0xc000098000, 0x15, 0x15)
/usr/local/opt/go/libexec/src/internal/fmtsort/sort.go:60 +0x34f
fmt.(*pp).printValue(0xc000144000, 0x10b44a0, 0xc000098000, 0x15, 0x76, 0x0)
/usr/local/opt/go/libexec/src/fmt/print.go:759 +0xd20
fmt.(*pp).printArg(0xc000144000, 0x10b44a0, 0xc000098000, 0x76)
/usr/local/opt/go/libexec/src/fmt/print.go:702 +0x2ba
fmt.(*pp).doPrintf(0xc000144000, 0x10d6754, 0x26, 0xc000189e50, 0x2, 0x2)
/usr/local/opt/go/libexec/src/fmt/print.go:1016 +0x158
fmt.Sprintf(0x10d6754, 0x26, 0xc000189e50, 0x2, 0x2, 0x1, 0xc00013c380)
/usr/local/opt/go/libexec/src/fmt/print.go:214 +0x66
log.Printf(0x10d6754, 0x26, 0xc000189e50, 0x2, 0x2)
/usr/local/opt/go/libexec/src/log/log.go:302 +0x53
agents/agent.(*Agent).listen(0xc000136040)
/Users/rcostumero/src/go/src/agents/agent/agent.go:112 +0x912
agents/agent.(*Agent).Register(0xc000136040)
/Users/rcostumero/src/go/src/agents/agent/agent.go:82 +0x33d
created by main.main
/Users/rcostumero/src/go/src/agents/main.go:25 +0x1ab
exit status 2

@ALTree

This comment has been minimized.

Copy link
Member

commented Aug 23, 2019

Thanks for the report.

I believe you are observing the issue described at #33275.

@ALTree

This comment has been minimized.

Copy link
Member

commented Aug 23, 2019

(And by the way, the patch for #33275 will only make the crash error more friendly. Your code is still racy, and thus invalid. You should fix this).

@rcostu

This comment has been minimized.

Copy link
Author

commented Aug 27, 2019

(And by the way, the patch for #33275 will only make the crash error more friendly. Your code is still racy, and thus invalid. You should fix this).

Indeed I had a race I hadn't detected. Solving it makes it working and the reported error no longer persist.

After looking at #33275, I think the error is the same and is a nicer error than the one got here.

Closing the issue, reopen if necessary. Thanks a lot!

@rcostu rcostu closed this Aug 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.