Navigation Menu

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: map crash at Store #33338

Closed
hemaolong opened this issue Jul 29, 2019 · 6 comments
Closed

sync: map crash at Store #33338

hemaolong opened this issue Jul 29, 2019 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@hemaolong
Copy link

Hi, it seems sync.Map crash randomly.
I can not reproduce this bug, it occurs about three times during last two months.

panic: assignment to entry in nil map

goroutine 213908 [running]:
sync.(*Map).Store(0xc0000d1818, 0x787340, 0xc01a6415e0, 0x786980, 0xc00026a548)
/usr/local/go/src/sync/map.go:160 +0x3c4
hive.(*SessionPipelineImpl).SetTag(0xc0000d17b8, 0x813957, 0x4, 0x786980, 0xc00026a548)
/data1/heml/hrg_deploy/src/hive/session.go:246 +0x9a
common.(*Room).Join(0xb2f2e0, 0x4e33a801b439e03, 0x884560, 0xc0000d17a0, 0x0)
/data1/heml/hrg_deploy/src/common/room.go:65 +0x196
main.(*preParser).OnSessionRead(0xc00000c5e0, 0x884560, 0xc0000d17a0, 0x7e4620, 0xc01af64fc0)
/data1/heml/hrg_deploy/src/mail/main.go:64 +0x1a4
hive.(*sessionImpl).runLogic(0xc0000d17a0)
/data1/heml/hrg_deploy/src/hive/session.go:205 +0x279
created by hive.(*sessionImpl).Start
/data1/heml/hrg_deploy/src/hive/session.go:86 +0xb1

go version: go version go1.10.4 linux/amd64
go env

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/mario/gopkg:/data1/heml/hrg_deploy"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
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-build743823671=/tmp/go-build -gno-record-gcc-switches"

Thanks!

@hemaolong
Copy link
Author

BTW, this is the code snippet

`/////////////////////////////////////////////////////////////
type SessionPipelineImpl struct {
decoder CodecDecoder
encoder CodecEncoder

decoderPostHandlers []CodecDecoderPost
encoderPreHandlers  []CodecEncoderPre

eventHandler SessionEventHandler

tags sync.Map

}

////////////////////////////////////////
func (self *SessionPipelineImpl) SetTag(k string, v interface{}) {
if v != nil {
self.tags.Store(k, v) // Line 246
} else {
self.tags.Delete(k)
}
}`

@agnivade agnivade changed the title sync map crash at Store sync: map crash at Store Jul 29, 2019
@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 29, 2019
@agnivade
Copy link
Contributor

agnivade commented Jul 29, 2019

Hi @hemaolong - It would be great if you could provide us with a self-contained code sample that shows the issue.

Have you tried running the code under the race detector to confirm there are no races ?

Are you copying the map anywhere in your code ?

Also, in your issue template, you haven't mentioned whether you have tried with 1.12.7 or not. Please try the latest release if possible and let us know.

@hemaolong
Copy link
Author

Hi @agnivade
Sorry, I can not reproduce it with self-contained code until now.

There is no map-copying in my codes(I think).

I will try the 1.12.7 and run under the race detector latter.

Thanks.

@hemaolong
Copy link
Author

I wonder if the code snippet cause the map-copying(fmt.Sprintf("%v", self.tags))?

func (self *sessionImpl) String() string {
	if self.conn == nil {
		return fmt.Sprintf("{addr:nil}")
	} else {
		return fmt.Sprintf("{addr:%v tag:%v}",
			self.conn.RemoteAddr(), 
			self.tags)
	}
}

/// 
type SessionPipelineImpl struct {
	decoder CodecDecoder
	encoder CodecEncoder

	decoderPostHandlers []CodecDecoderPost
	encoderPreHandlers  []CodecEncoderPre

	eventHandler SessionEventHandler

	tags sync.Map
}

@hemaolong
Copy link
Author

Hi @agnivade
It is my mistake. There are several data race in my codes.No new crash until now after fix the race codes.
It seems that the "ClearTag"(used to clear the sync.Map) crash the program, which cause the map-copying.

Thanks for your help!

==================
==================
WARNING: DATA RACE
func (self *sessionImpl) String() string {
	if self.conn == nil {
		return fmt.Sprintf("{addr:nil}")
	} else {
		return fmt.Sprintf("{addr:%v tag:%v}",
			self.conn.RemoteAddr(), self.tags)
	}
}
==================
==================
WARNING: DATA RACE
func (self *SessionPipelineImpl) ClearTag() {
	self.tags = sync.Map{}
}

@ALTree
Copy link
Member

ALTree commented Jul 29, 2019

Nice. Closing here, then.

@ALTree ALTree closed this as completed Jul 29, 2019
@golang golang locked and limited conversation to collaborators Jul 28, 2020
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.
Projects
None yet
Development

No branches or pull requests

4 participants