Skip to content
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

sync: RWMutex.RLock failed return panic #47004

Closed
Mr1X opened this issue Jul 1, 2021 · 6 comments
Closed

sync: RWMutex.RLock failed return panic #47004

Mr1X opened this issue Jul 1, 2021 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@Mr1X
Copy link

Mr1X commented Jul 1, 2021

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

$ go version
go1.13.12 linux/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://mirrors.aliyun.com/goproxy/"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build239103222=/tmp/go-build"

What did you do?

type TradeTimeCal struct {
	remoteURI     string
	cLock         sync.RWMutex
}

func NewTradeTimeCal(remoteURI string, updateHour int) *TradeTimeCal {
	newone := &TradeTimeCal{
		remoteURI:  remoteURI,
		updateHour: updateHour,
	}
	return newone
}

func (this *TradeTimeCal) IsTradingday(exchangid, tradeday string) bool {
	this.cLock.RLock()
        // do something
	this.cLock.RUnlock()
	if !ok {
		return false
	}
	return true
}

What did you expect to see?

when I call the function IsTradingday,i want RLock success every time

What did you see instead?

when I call the function IsTradingday, it return panic accidental,Not necessarily

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xc00edb]
goroutine 57 [running]:
sync.(*RWMutex).RLock(...)
	/usr/local/go/src/sync/rwmutex.go:48
jcqts/tradetimesdk.(*TradeTimeCal).IsTradingday(0x0, 0xc00037a390, 0xa, 0xc11622c430, 0x8, 0xc11622c430)
	/tradetimesdk/tradetimesdk.go:114 +0x2b
@davecheney
Copy link
Contributor

This looks like memory corruption. Have you tried running your program under the race detector? See https://blog.golang.org/race-detector .

@dmitshur dmitshur changed the title sync/RWMutex RLock failed return panic sync: RWMutex.RLock failed return panic Jul 1, 2021
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 1, 2021
@dmitshur
Copy link
Contributor

dmitshur commented Jul 1, 2021

Is this a problem you're able to reproduce, or was this just a single occurrence? If you're able to reproduce, does it still happen with a newer Go version (1.16 or 1.15)?

@dmitshur dmitshur added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 1, 2021
@Mr1X
Copy link
Author

Mr1X commented Jul 2, 2021

Is this a problem you're able to reproduce, or was this just a single occurrence? If you're able to reproduce, does it still happen with a newer Go version (1.16 or 1.15)?

I'm trying to upgrade the go version in production, thank you

@Mr1X
Copy link
Author

Mr1X commented Jul 2, 2021

This looks like memory corruption. Have you tried running your program under the race detector? See https://blog.golang.org/race-detector .

I'll try upgrade go version and run program under the race detector. Thank you

@BenLubar
Copy link

The stack trace shows the first argument to IsTradingDay being 0x0, so this.cLock is dereferencing a nil pointer.

@davecheney
Copy link
Contributor

Closing as answered.

@golang golang locked and limited conversation to collaborators Jul 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants