mirror of https://github.com/grpc/grpc-java.git
Fix flake in ManagedChannelImplTest.transportFailsOnStart
The scheduling on another thread led to a race where sometimes the future wasn't completed by the time isDone() was checked in ClientCallImpl causing the usage of DelayedStream, which really messed up what the test was trying to do.
This commit is contained in:
parent
942f4c99d8
commit
16c4c49e94
|
|
@ -150,16 +150,7 @@ final class TransportSet {
|
||||||
Preconditions.checkState(!shutdown, "Already shut down");
|
Preconditions.checkState(!shutdown, "Already shut down");
|
||||||
Preconditions.checkState(reconnectTask == null || reconnectTask.isDone(),
|
Preconditions.checkState(reconnectTask == null || reconnectTask.isDone(),
|
||||||
"previous reconnectTask is not done");
|
"previous reconnectTask is not done");
|
||||||
long delayMillis;
|
Runnable createTransportRunnable = new Runnable() {
|
||||||
if (reconnectPolicy == null) {
|
|
||||||
// First connect attempt
|
|
||||||
delayMillis = 0;
|
|
||||||
reconnectPolicy = backoffPolicyProvider.get();
|
|
||||||
} else {
|
|
||||||
// Reconnect attempts
|
|
||||||
delayMillis = reconnectPolicy.nextBackoffMillis();
|
|
||||||
}
|
|
||||||
reconnectTask = scheduledExecutor.schedule(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
|
|
@ -177,7 +168,18 @@ final class TransportSet {
|
||||||
"failed to set the new transport to the future");
|
"failed to set the new transport to the future");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, delayMillis, TimeUnit.MILLISECONDS);
|
};
|
||||||
|
if (reconnectPolicy == null) {
|
||||||
|
// First connect attempt
|
||||||
|
reconnectPolicy = backoffPolicyProvider.get();
|
||||||
|
createTransportRunnable.run();
|
||||||
|
reconnectTask = null;
|
||||||
|
} else {
|
||||||
|
// Reconnect attempts
|
||||||
|
long delayMillis = reconnectPolicy.nextBackoffMillis();
|
||||||
|
reconnectTask = scheduledExecutor.schedule(
|
||||||
|
createTransportRunnable, delayMillis, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -196,7 +198,9 @@ final class TransportSet {
|
||||||
if (transports.isEmpty()) {
|
if (transports.isEmpty()) {
|
||||||
runCallback = true;
|
runCallback = true;
|
||||||
}
|
}
|
||||||
|
if (reconnectTask != null) {
|
||||||
reconnectTask.cancel(false);
|
reconnectTask.cancel(false);
|
||||||
|
}
|
||||||
// else: the callback will be run once all transports have been terminated
|
// else: the callback will be run once all transports have been terminated
|
||||||
}
|
}
|
||||||
if (savedActiveTransportFuture != null) {
|
if (savedActiveTransportFuture != null) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue