Skip to content

hash/maphash: hashing channels with purego impl. of maphash.Comparable panics #73657

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

Open
Snawoot opened this issue May 10, 2025 · 5 comments · May be fixed by #73660
Open

hash/maphash: hashing channels with purego impl. of maphash.Comparable panics #73657

Snawoot opened this issue May 10, 2025 · 5 comments · May be fixed by #73660
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@Snawoot
Copy link

Snawoot commented May 10, 2025

Go version

go version go1.24.2 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1565376817=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib64/go/1.24'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib64/go/1.24/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Minimal example to reproduce:

package main

import (
	"hash/maphash"
)

func main() {
	maphash.Comparable(maphash.MakeSeed(), make(chan struct{}))
}

What did you see happen?

Run with go run -tags purego main.go causes panic:

$ go run -tags purego main.go
panic: maphash: hash of unhashable type chan struct {}

goroutine 1 [running]:
hash/maphash.appendT(0xc0000a0e78, {0x497e40?, 0xc000096070?, 0x4112fe?})
	/usr/lib64/go/1.24/src/hash/maphash/maphash_purego.go:176 +0x6f7
hash/maphash.writeComparable[...](0xc0000a0e78?, 0x1c0000a0f08)
	/usr/lib64/go/1.24/src/hash/maphash/maphash_purego.go:111 +0x31
hash/maphash.comparableHash[...](0x0?, {0x552308?})
	/usr/lib64/go/1.24/src/hash/maphash/maphash_purego.go:105 +0x58
hash/maphash.Comparable[...](...)
	/usr/lib64/go/1.24/src/hash/maphash/maphash.go:289
main.main()
	/home/user/src/1/main.go:8 +0x3d
exit status 2

The problem is that purego implementation of maphash doesn't handle reflect.Chan kind of values: https://cs.opensource.google/go/go/+/refs/tags/go1.24.3:src/hash/maphash/maphash_purego.go;l=115-175

I can submit pull request which will make it handle reflect.Chan as every other pointer types, hashing v.Pointer() value.

What did you expect to see?

No panic like with regular go run main.go command.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label May 10, 2025
@qiulaidongfeng
Copy link
Member

Thanks for report.
You can send the fix, See https://go.dev/doc/contribute.

Snawoot added a commit to Snawoot/go that referenced this issue May 10, 2025
Make maphash properly hash channels as represented by pointer.

Fixes golang#73657
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/671655 mentions this issue: hash/maphash: hash channels in purego version of maphash.Comparable

@qiulaidongfeng
Copy link
Member

@gopherbot please consider this for backport to 1.24. This issue causes when using pruego build tags, maphash.Comparable cannot handle channal type correctly. There is no solution.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #73669 (for 1.24).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants