Skip to content

testing/synctest: receive on synctest channel from outside bubble when not using synctest #73648

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
SilvioRispoliAtElectroluxDotCom opened this issue May 9, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@SilvioRispoliAtElectroluxDotCom

Go version

go version go1.24.3 windows/amd64

Output of go env in your module/workspace:

set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=1
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\RispoSil\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\RispoSil\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\RispoSil\AppData\Local\Temp\go-build2564291241=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\RispoSil\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\RispoSil\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\RispoSil\scoop\apps\go\current
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\RispoSil\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\RispoSil\scoop\apps\go\current\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.3
set GOWORK=
set PKG_CONFIG=pkg-config

REM Some items might have been omitted as per industry secrets

What did you do?

I executed my project built binary. The project makes heavy usage of channels and has "hopper" strategies to collect items from many channels and output them into one (which I think is the reason for the panic).

The "hopper" strategy (that I call DeMultiplexer) looks something like this:

package tools

import (
	"context"
	"fmt"
)

type DeMultiplexer[T any] struct {
	sources []chan T
}

func CreateDeMultiplexer[T any]() DeMultiplexer[T] {
	return DeMultiplexer[T]{
		sources: []chan T{},
	}
}

func (ec *DeMultiplexer[T]) Subscribe(source chan T) {
	ec.sources = append(ec.sources, source)
}

func (ec *DeMultiplexer[T]) Run(ctx context.Context) (chan T, error) {
	collected := make(chan T, 1)

	if err := ctx.Err(); err != nil {
		close(collected)
		return collected, fmt.Errorf("abort DeMultiplexer due to error: %w", context.Cause(ctx))
	}

	go func() {
		for {
			select {
			case <-ctx.Done():
				return

			default:
				for _, ch := range ec.sources {
					select {
					case el := <-ch:
						collected <- el
					default:

					}
				}
			}
		}
	}()

	return collected, nil
}

What did you see happen?

At times the runtime panics in a non repeatable manner. An example stacktrace:

panic: receive on synctest channel from outside bubble

goroutine 24 [running]:
the/project/tools.(*DeMultiplexer[...]).Run.func1()
        C:/path/to/project/tools/demultiplexer.go:39 +0xab
created by the/project/tools.(*DeMultiplexer[...]).Run in goroutine 1
        C:/path/to/project/tools/demultiplexer.go:30 +0x12a

What did you expect to see?

Why this, albeit being quite lousy work, snippet of code is able to generate a panic that should happen only during tests, and only by manually enabling experimental features (which I did not do) ?

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label May 9, 2025
@seankhliao seankhliao changed the title go/synctest: outside bubble channel recv panic from outside tests testing/synctest: receive on synctest channel from outside bubble when not using synctest. May 9, 2025
@seankhliao seankhliao changed the title testing/synctest: receive on synctest channel from outside bubble when not using synctest. testing/synctest: receive on synctest channel from outside bubble when not using synctest May 9, 2025
@seankhliao
Copy link
Member

I think we need a reproducer.

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 9, 2025
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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants