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

encounter concurrent map writes issue #471

Closed
wanmingchao001 opened this issue Jan 17, 2022 · 2 comments
Closed

encounter concurrent map writes issue #471

wanmingchao001 opened this issue Jan 17, 2022 · 2 comments

Comments

@wanmingchao001
Copy link

wanmingchao001 commented Jan 17, 2022

In GossipSubRouter these are many thread-unsafe maps, such as peers, direct, etc.

type GossipSubRouter struct {
	p        *PubSub
	peers    map[peer.ID]protocol.ID          // peer protocols
	direct   map[peer.ID]struct{}             // direct peers
	mesh     map[string]map[peer.ID]struct{}  // topic meshes
        ....
}

I forked this project (v0.3.5) and it panic randomly due to concurrent map writes issue. Plz see the detail as follows.

fatal error: concurrent map writes

goroutine 602 [running]:
runtime.throw(0x262c7fd, 0x15)
/usr/local/go/src/runtime/panic.go:1116 +0x72 fp=0xc01db9b5c0 sp=0xc01db9b590 pc=0x4ff272
runtime.mapdelete_faststr(0x22355a0, 0xc00f8b1410, 0xc00fb7e5a0, 0x22)
/usr/local/go/src/runtime/map_faststr.go:377 +0x34c fp=0xc01db9b628 sp=0xc01db9b5c0 pc=0x4dc06c
chainmaker.org/chainmaker/libp2p-pubsub.(*GossipSubRouter).RemovePeer(0xc00f97e000, 0xc00fb7e5a0, 0x22)
/root/gocode/pkg/mod/chainmaker.org/chainmaker/libp2p-pubsub@v1.0.0/gossipsub.go:483 +0x138 fp=0xc01db9b700 sp=0xc01db9b628 pc=0x16d1e18
chainmaker.org/chainmaker/libp2p-pubsub.(*PubSub).processLoop(0xc0002da1a0, 0x2a19a00, 0xc000044118)
/root/gocode/pkg/mod/chainmaker.org/chainmaker/libp2p-pubsub@v1.0.0/pubsub.go:615 +0x1759 fp=0xc01db9bfc8 sp=0xc01db9b700 pc=0x16e4639
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc01db9bfd0 sp=0xc01db9bfc8 pc=0x538661
created by chainmaker.org/chainmaker/libp2p-pubsub.NewPubSub
/root/gocode/pkg/mod/chainmaker.org/chainmaker/libp2p-pubsub@v1.0.0/pubsub.go:296 +0xc09

It seems that when removing peer from the peers map, other go routine reads it.

Does anyone see the same problem?

@vyzo
Copy link
Collaborator

vyzo commented Jan 17, 2022 via email

@wanmingchao001
Copy link
Author

@vyzo I got it. I invoked the RemovePeer() method in other go routine directly, and caused this issue. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants