forked from tendermint/tendermint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
p2p: Remove data race bug in netaddr stringer (tendermint#5048)
## Description Remove concurrent write access bug by removing the memoized string representation of a `NetAddress`. Closes: tendermint#5047
- Loading branch information
1 parent
7a1ee66
commit e59378b
Showing
2 changed files
with
33 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,35 @@ package p2p | |
|
||
import ( | ||
"net" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNetAddress_String(t *testing.T) { | ||
tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:8080") | ||
require.Nil(t, err) | ||
|
||
netAddr := NewNetAddress("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", tcpAddr) | ||
|
||
var wg sync.WaitGroup | ||
|
||
for i := 0; i < 10; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
_ = netAddr.String() | ||
}() | ||
} | ||
|
||
wg.Wait() | ||
|
||
s := netAddr.String() | ||
require.Equal(t, "[email protected]:8080", s) | ||
} | ||
|
||
func TestNewNetAddress(t *testing.T) { | ||
tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:8080") | ||
require.Nil(t, err) | ||
|