You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
xds/resolver_test: fix flaky test ResolverBadServiceUpdate_NACKedWithoutCache (#8521)
Fixes: #8435
### root cause of issue:
- I think there was a race condition when channel communicates between
the xDS resolver and test infrastructure
- insufficient buffer size: original channels (stateCh and errCh) had
only buffer size of 1
- blocking sends: When buffer is full, the resolver would block trying
to send the next update
- test deadlock: test infra might be waiting for a specific update while
the resolver was blocked trying to send a different update, creating a
deadlock
### Changes
1) Increased buffer size (1 → 10):
``` go
stateCh := make(chan resolver.State, 10)
errCh := make(chan error, 10)
```
2) Non-blocking send pattern:
``` go
select {
case stateCh <- s: // the resolver try to send updates
default: // If channel is full, drain old message and retry
select {
case <-stateCh:
stateCh <- s
default:
}
}
```
- make it drain old messages preventing the resolver from blocking and just keeping the most latest updates.
3) Cleanup with draining goroutines:
``` go
go func() {
for range stateCh { } // Drain any remaining messages
}()
```
- it ensures the resolver never blocks on sends and prevents `goroutine leaks` during test cleanup.
RELEASE NOTES: N/A
0 commit comments