Skip to content

Go race detector false positive due to shadowed variable #62289

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

Closed
tiborvass opened this issue Aug 25, 2023 · 1 comment
Closed

Go race detector false positive due to shadowed variable #62289

tiborvass opened this issue Aug 25, 2023 · 1 comment

Comments

@tiborvass
Copy link

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

$ go version
go version go1.21.0 darwin/arm64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/tibor/Library/Caches/go-build'
GOENV='/Users/tibor/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/tibor/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/tibor/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/2y/mtr77k3n3_d_xqpqs9j26gb40000gn/T/go-build2848548716=/tmp/go-build -gno-record-gcc-switches -fno-common'
uname -v: Darwin Kernel Version 22.5.0: Thu Jun  8 22:21:34 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8112
ProductName:		macOS
ProductVersion:		13.4.1
ProductVersionExtra:	(c)
BuildVersion:		22F770820d
lldb --version: lldb-1403.0.17.67
Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)

What did you do?

$ cat repro.go
package main

import (
	"context"
)

func f(ctx context.Context) (context.Context, error) {
	return ctx, nil
}

func main() {
	ctx := context.Background()
	go func() {
		_ = ctx
	}()
	ctx, err := f(ctx)
	_ = err
	_ = ctx
}
$ go run -race repro.go

What did you expect to see?

exit code 0

What did you see instead?

==================
WARNING: DATA RACE
Read at 0x00c0001160c0 by goroutine 5:
  main.main.func1()
      repro.go:14 +0x2c

Previous write at 0x00c0001160c0 by main goroutine:
  main.main()
      repro.go:16 +0x114

Goroutine 5 (running) created at:
  main.main()
      repro.go:13 +0xf4
==================
Found 1 data race(s)
exit status 66
@seankhliao
Copy link
Member

that's a true positive, ctx, err := doesn't create a new ctx

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2023
@golang golang locked and limited conversation to collaborators Aug 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants