Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

pss: fix concurrent map read and map write on pubKeyRWPool #1870

Merged
merged 1 commit into from
Oct 14, 2019

Conversation

janos
Copy link
Member

@janos janos commented Oct 7, 2019

This PR adds read protection to pool maps in pss handler. Map is protected on write operations, but not on read resulting the following panic:

WARN [10-04|12:12:29.393|github.com/ethersphere/swarm/pss/crypto/crypto.go:183] Size of payload field                    size=1
WARN [10-04|12:12:29.395|github.com/ethersphere/swarm/pss/crypto/crypto.go:183] Size of payload field                    size=1
WARN [10-04|12:12:29.398|github.com/ethersphere/swarm/pss/crypto/crypto.go:183] Size of payload field                    size=1
WARN [10-04|12:12:29.399|github.com/ethersphere/swarm/pss/crypto/crypto.go:183] Size of payload field                    size=1
fatal error: concurrent map read and map write

goroutine 164 [running]:
runtime.throw(0xdbbf54, 0x21)
    /usr/local/go/src/runtime/panic.go:774 +0x72 fp=0xc0013678a0 sp=0xc001367870 pc=0x435ed2
runtime.mapaccess1_faststr(0xc6cd40, 0xc000589830, 0xc0005acfc0, 0x84, 0x3)
    /usr/local/go/src/runtime/map_faststr.go:21 +0x44f fp=0xc001367910 sp=0xc0013678a0 pc=0x41922f
github.com/ethersphere/swarm/pss.(*Protocol).Handle(0xc000585700, 0xc0013ae5a2, 0x8, 0x59, 0xc000573140, 0xc000573101, 0xc0005acfc0, 0x84, 0xc000573140, 0xc0000e5180)
    /home/rafa/go/src/github.com/ethersphere/swarm/pss/protocol.go:187 +0x1a2 fp=0xc0013679c0 sp=0xc001367910 pc=0xb513c2
github.com/ethersphere/swarm/pss.(*Protocol).Handle-fm(0xc0013ae5a2, 0x8, 0x59, 0xc000573140, 0xc0013c8001, 0xc0005acfc0, 0x84, 0x0, 0x0)
    /home/rafa/go/src/github.com/ethersphere/swarm/pss/protocol.go:166 +0x7c fp=0xc001367a20 sp=0xc0013679c0 pc=0xb82b9c
github.com/ethersphere/swarm/pss.(*Pss).executeHandlers(0xc000266000, 0xc04e61647f, 0xc0013ae5a2, 0x8, 0x59, 0xc000570160, 0x20, 0x20, 0x10000, 0xc0005acfc0, ...)
    /home/rafa/go/src/github.com/ethersphere/swarm/pss/pss.go:614 +0x29e fp=0xc001367b28 sp=0xc001367a20 pc=0xb56b9e
github.com/ethersphere/swarm/pss.(*Pss).process(0xc000266000, 0xc0013b22c0, 0xc001350000, 0x0, 0x0)
    /home/rafa/go/src/github.com/ethersphere/swarm/pss/pss.go:586 +0x23c fp=0xc001367c68 sp=0xc001367b28 pc=0xb564fc
github.com/ethersphere/swarm/pss.(*Pss).handlePssMsg(0xc000266000, 0xf17860, 0xc0000b0010, 0xc0013b22c0, 0x0, 0x0)
    /home/rafa/go/src/github.com/ethersphere/swarm/pss/pss.go:543 +0x662 fp=0xc001367f20 sp=0xc001367c68 pc=0xb557e2
github.com/ethersphere/swarm/pss.(*Pss).handle.func1(0xc89ee0, 0xc0013b22c0, 0xc00053c0f0, 0xc000266000, 0xf17860, 0xc0000b0010)
    /home/rafa/go/src/github.com/ethersphere/swarm/pss/pss.go:487 +0x85 fp=0xc001367fb0 sp=0xc001367f20 pc=0xb7c125
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc001367fb8 sp=0xc001367fb0 pc=0x4660b1
created by github.com/ethersphere/swarm/pss.(*Pss).handle
    /home/rafa/go/src/github.com/ethersphere/swarm/pss/pss.go:481 +0x71

[...]

goroutine 112 [select]:
github.com/ethersphere/swarm/pss.NewPingProtocol.func1.1(0xc0005b4960, 0xc00058c660, 0xc0000953e0)
    /home/rafa/go/src/github.com/ethersphere/swarm/pss/ping.go:82 +0xb4
created by github.com/ethersphere/swarm/pss.NewPingProtocol.func1
    /home/rafa/go/src/github.com/ethersphere/swarm/pss/ping.go:80 +0x1f4

FAIL    github.com/ethersphere/swarm/pss    1.166s

This panic was reported by @mortelli https://beehive.ethswarm.org/swarm/pl/butadain33bjzyasrkqoyhtdah, but I could not reproduce it.

@janos janos requested review from nonsense and nolash October 7, 2019 13:07
@janos janos self-assigned this Oct 7, 2019
@janos janos added this to Backlog in Swarm Core - Sprint planning via automation Oct 7, 2019
Copy link
Contributor

@kortatu kortatu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@acud acud moved this from Backlog to In review (includes Documentation) in Swarm Core - Sprint planning Oct 13, 2019
@janos janos merged commit 6dfe222 into master Oct 14, 2019
Swarm Core - Sprint planning automation moved this from In review (includes Documentation) to Done Oct 14, 2019
@janos janos deleted the fix-pss-concurrent-map-read-and-write branch October 14, 2019 11:46
@acud acud added this to the 0.5.3 milestone Nov 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants