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
de226f26e4
commit
bbf1a116f6
|
@ -237,7 +237,7 @@ jobs:
|
||||||
command: |
|
command: |
|
||||||
mkdir -p $TEST_RESULTS_DIR /tmp/jsonfile
|
mkdir -p $TEST_RESULTS_DIR /tmp/jsonfile
|
||||||
pkgs="$(go list ./... | \
|
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/')"
|
grep -E -v '^github.com/hashicorp/consul/command/')"
|
||||||
gotestsum \
|
gotestsum \
|
||||||
--jsonfile /tmp/jsonfile/go-test-race.log \
|
--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
|
// unblock the recv chan to simulate recv error when client disconnects
|
||||||
if e.stream != nil && e.stream.recvCh != nil {
|
if e.stream != nil && e.stream.recvCh != nil {
|
||||||
close(e.stream.recvCh)
|
close(e.stream.recvCh)
|
||||||
e.stream.recvCh = nil
|
e.stream = nil
|
||||||
}
|
}
|
||||||
if e.cancel != nil {
|
if e.cancel != nil {
|
||||||
e.cancel()
|
e.cancel()
|
||||||
|
|
Loading…
Reference in New Issue