Skip to content

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

Closed
@Snawoot

Description

@Snawoot

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.

Activity

added
BugReportIssues describing a possible bug in the Go implementation.
on May 10, 2025
qiulaidongfeng

qiulaidongfeng commented on May 10, 2025

@qiulaidongfeng
Member

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

added a commit that references this issue on May 10, 2025
1ee053e
gopherbot

gopherbot commented on May 10, 2025

@gopherbot
Contributor

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

qiulaidongfeng

qiulaidongfeng commented on May 11, 2025

@qiulaidongfeng
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

gopherbot commented on May 11, 2025

@gopherbot
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.

added
NeedsFixThe path to resolution is known, but the work has not been done.
on May 12, 2025
added this to the Go1.25 milestone on May 12, 2025
added a commit that references this issue on May 20, 2025
1635aed
added a commit that references this issue on May 24, 2025
973b70e
gopherbot

gopherbot commented on May 28, 2025

@gopherbot
Contributor

Change https://go.dev/cl/676817 mentions this issue: [release-branch.go1.24] hash/maphash: hash channels in purego version of maphash.Comparable

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @mknyszek@Snawoot@gopherbot@qiulaidongfeng@gabyhelp

      Issue actions

        hash/maphash: hashing channels with purego impl. of maphash.Comparable panics · Issue #73657 · golang/go