mirror of https://github.com/grpc/grpc-java.git
Fixing flaky test Http2NettyTest.deadlineExceeded()
This test occasionally flakes due to the way the deadline timer cancels the stream. Stream cancellation immediately closes the outbound status, disallowing the sending of further messages. The true cancellation is done sometime later in the transport thread in Netty. So there is a race between closing the outbound status and performing the actual cancellation where sent messages will fail with the wrong status.
This commit is contained in:
parent
ea4eed57b9
commit
7c2ff632cd
|
@ -60,6 +60,7 @@ public abstract class AbstractClientStream<IdT> extends AbstractStream<IdT>
|
|||
private Status status;
|
||||
private Metadata trailers;
|
||||
private Runnable closeListenerTask;
|
||||
private volatile boolean cancelled;
|
||||
|
||||
protected AbstractClientStream(WritableBufferAllocator bufferAllocator,
|
||||
ClientStreamListener listener,
|
||||
|
@ -293,11 +294,16 @@ public abstract class AbstractClientStream<IdT> extends AbstractStream<IdT>
|
|||
@Override
|
||||
public final void cancel(Status reason) {
|
||||
checkArgument(CANCEL_REASONS.contains(reason.getCode()), "Invalid cancellation reason");
|
||||
outboundPhase(Phase.STATUS);
|
||||
cancelled = true;
|
||||
sendCancel(reason);
|
||||
dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isReady() {
|
||||
return !cancelled && super.isReady();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the stream and send a stream cancellation message to the remote server, if necessary.
|
||||
* Can be called by either the application or transport layers. This method is safe to be called
|
||||
|
|
|
@ -176,7 +176,7 @@ public abstract class AbstractStream<IdT> implements Stream {
|
|||
}
|
||||
|
||||
@Override
|
||||
public final boolean isReady() {
|
||||
public boolean isReady() {
|
||||
if (listener() != null && outboundPhase() != Phase.STATUS) {
|
||||
synchronized (onReadyLock) {
|
||||
return allocated && numSentBytesQueued < onReadyThreshold;
|
||||
|
|
Loading…
Reference in New Issue