Closed
Description
Using context.WithCancel cancellation may happen asynchronously however it is not documented.
A facilitated example of this happening: https://play.golang.org/p/ji63DpfJmMg (running locally it sometimes finishes in time). The corresponding code triggering this behavior is in https://github.com/golang/go/blob/master/src/context/context.go#L262.
I was cancelling a context and expected all child-contexts to be cancelled immediately. This caused a "bug hunt". I'm not sure whether there is a way to fix this, so it's probably worth at least documenting this asynchronous behavior.
Details
$ go version go version go1.13beta1 windows/amd64
go env
Output
$ go env set GO111MODULE= set GOARCH=amd64 set GOBIN= set GOCACHE=Z:\gocache set GOENV=C:\Users\egone\AppData\Roaming\go\env set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GONOPROXY= set GONOSUMDB= set GOOS=windows set GOPATH=F:\Go set GOPRIVATE= set GOPROXY=https://proxy.golang.org,direct set GOROOT=c:\go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=c:\go\pkg\tool\windows_amd64 set GCCGO=gccgo set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD= set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=Z:\Temp\go-build959337302=/tmp/go-build -gno-record-gcc-switches