hashicorp / hashicorp/memberlist

Data race in state.go:1135

Open
#306 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
4.1k
Forks
478
Avg merge
15h 58m
Merged PRs (30d)
3

Description

Hi. I've detected the following data race in memberlist 0.5.0:

```
==================
WARNING: DATA RACE
Write at 0x00c000693728 by goroutine 53:
github.com/hashicorp/memberlist.(*Memberlist).aliveNode()
.../vendor/github.com/hashicorp/memberlist/state.go:1135 +0x2e3b
github.com/hashicorp/memberlist.(*Memberlist).handleAlive()
.../vendor/github.com/hashicorp/memberlist/net.go:738 +0x69a
github.com/hashicorp/memberlist.(*Memberlist).packetHandler()
.../vendor/github.com/hashicorp/memberlist/net.go:513 +0x1b9
github.com/hashicorp/memberlist.newMemberlist.gowrap3()
.../vendor/github.com/hashicorp/memberlist/memberlist.go:235 +0x33

Previous read at 0x00c000693728 by goroutine 146:
github.com/hashicorp/memberlist.(*Node).Address()
.../vendor/github.com/hashicorp/memberlist/state.go:58 +0x6b
...

Goroutine 53 (running) created at:
github.com/hashicorp/memberlist.newMemberlist()
.../vendor/github.com/hashicorp/memberlist/memberlist.go:235 +0x1aea
github.com/hashicorp/memberlist.Create()
.../vendor/github.com/hashicorp/memberlist/memberlist.go:246 +0x2e
...

Goroutine 146 (running) created at:
...
==================
```

The idea is that memberlist `Members()` returns a list of pointers to `Memberlist::nodes` array items. Then the external user's code is allowed to read them without any locking. But at the same time, they may get modified internally in Memberlist, resulting in a data race.

Not sure if it's a critical issue and how hard it would be to stumble on it in production. But it's still a race...

Contributor guide

Open the contributing guide

Research direction

Trace Members() and Node.Address() in state.go, then compare the read at state.go:58 with the write in aliveNode() at state.go:1135. Reproduce the reported access with Go's race detector and confirm that the externally returned node data can be read safely while internal membership handling continues.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.