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:
nmittler 2015-09-24 16:22:46 -07:00
parent ea4eed57b9
commit 7c2ff632cd
2 changed files with 8 additions and 2 deletions

View File

@ -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

View File

@ -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;