mirror of https://github.com/status-im/consul.git
xds: Fix data race
TestEnvoy.Close used e.stream.recvCh == nil to indicate the channel had already been closed, so that TestEnvoy.Close can be called multiple times. The recvCh was not protected by a lock, so setting it to nil caused a data race with any goroutine trying to read from the channel. Instead set the stream to nil. The stream is guarded by a lock, so it does not race. This change allows us to test the agent/xds package using -race.
This commit is contained in:
parent
375aed5ed6
commit
2e2ee41390
|
@ -237,7 +237,7 @@ jobs:
|
|||
command: |
|
||||
mkdir -p $TEST_RESULTS_DIR /tmp/jsonfile
|
||||
pkgs="$(go list ./... | \
|
||||
grep -E -v '^github.com/hashicorp/consul/agent(/consul|/local|/xds|/routine-leak-checker)?$' | \
|
||||
grep -E -v '^github.com/hashicorp/consul/agent(/consul|/local|/routine-leak-checker)?$' | \
|
||||
grep -E -v '^github.com/hashicorp/consul/command/')"
|
||||
gotestsum \
|
||||
--jsonfile /tmp/jsonfile/go-test-race.log \
|
||||
|
|
|
@ -189,7 +189,7 @@ func (e *TestEnvoy) Close() error {
|
|||
// unblock the recv chan to simulate recv error when client disconnects
|
||||
if e.stream != nil && e.stream.recvCh != nil {
|
||||
close(e.stream.recvCh)
|
||||
e.stream.recvCh = nil
|
||||
e.stream = nil
|
||||
}
|
||||
if e.cancel != nil {
|
||||
e.cancel()
|
||||
|
|
Loading…
Reference in New Issue