mirror of https://github.com/grpc/grpc-java.git
Move retrieval of elapsed time in handleRpcStreamClosed to make TSan happy (#9923)
* In `handleRpcStreamClosed()`, move retry handling to before the call to `xdsResponseHandler.handleStreamClosed()` so that TSan doesn't report a race condition that is completely meaningless. fixes #9920
This commit is contained in:
parent
c367b267c6
commit
95a44e0592
|
@ -330,6 +330,17 @@ final class AbstractXdsClient {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (responseReceived || retryBackoffPolicy == null) {
|
||||||
|
// Reset the backoff sequence if had received a response, or backoff sequence
|
||||||
|
// has never been initialized.
|
||||||
|
retryBackoffPolicy = backoffPolicyProvider.get();
|
||||||
|
}
|
||||||
|
// Need this here to avoid tsan race condition in XdsClientImplTestBase.sendToNonexistentHost
|
||||||
|
long elapsed = stopwatch.elapsed(TimeUnit.NANOSECONDS);
|
||||||
|
long delayNanos = Math.max(0, retryBackoffPolicy.nextBackoffNanos() - elapsed);
|
||||||
|
rpcRetryTimer = syncContext.schedule(
|
||||||
|
new RpcRetryTask(), delayNanos, TimeUnit.NANOSECONDS, timeService);
|
||||||
|
|
||||||
checkArgument(!error.isOk(), "unexpected OK status");
|
checkArgument(!error.isOk(), "unexpected OK status");
|
||||||
String errorMsg = error.getDescription() != null
|
String errorMsg = error.getDescription() != null
|
||||||
&& error.getDescription().equals(CLOSED_BY_SERVER)
|
&& error.getDescription().equals(CLOSED_BY_SERVER)
|
||||||
|
@ -341,17 +352,7 @@ final class AbstractXdsClient {
|
||||||
xdsResponseHandler.handleStreamClosed(error);
|
xdsResponseHandler.handleStreamClosed(error);
|
||||||
cleanUp();
|
cleanUp();
|
||||||
|
|
||||||
if (responseReceived || retryBackoffPolicy == null) {
|
|
||||||
// Reset the backoff sequence if had received a response, or backoff sequence
|
|
||||||
// has never been initialized.
|
|
||||||
retryBackoffPolicy = backoffPolicyProvider.get();
|
|
||||||
}
|
|
||||||
long delayNanos = Math.max(
|
|
||||||
0,
|
|
||||||
retryBackoffPolicy.nextBackoffNanos() - stopwatch.elapsed(TimeUnit.NANOSECONDS));
|
|
||||||
logger.log(XdsLogLevel.INFO, "Retry ADS stream in {0} ns", delayNanos);
|
logger.log(XdsLogLevel.INFO, "Retry ADS stream in {0} ns", delayNanos);
|
||||||
rpcRetryTimer = syncContext.schedule(
|
|
||||||
new RpcRetryTask(), delayNanos, TimeUnit.NANOSECONDS, timeService);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void close(Exception error) {
|
private void close(Exception error) {
|
||||||
|
|
Loading…
Reference in New Issue