diff --git a/core/src/main/java/com/google/net/stubby/ChannelImpl.java b/core/src/main/java/com/google/net/stubby/ChannelImpl.java index acf48615e7..cb3645d69b 100644 --- a/core/src/main/java/com/google/net/stubby/ChannelImpl.java +++ b/core/src/main/java/com/google/net/stubby/ChannelImpl.java @@ -52,9 +52,13 @@ public final class ChannelImpl extends AbstractService implements Channel { @Override protected synchronized void doStop() { - activeTransport.stopAsync(); - activeTransport = null; - // The last TransportListener will call notifyStopped(). + if (activeTransport != null) { + activeTransport.stopAsync(); + activeTransport = null; + // The last TransportListener will call notifyStopped(). + } else { + notifyStopped(); + } } @Override @@ -115,7 +119,7 @@ public final class ChannelImpl extends AbstractService implements Channel { private class CallImpl extends Call { private final MethodDescriptor method; - private final SerializingExecutor executor; + private final SerializingExecutor callExecutor; // TODO(user): Consider moving flow control notification/management to Call itself. private final Collection> inProcessFutures = Collections.synchronizedSet(new HashSet>()); @@ -123,7 +127,7 @@ public final class ChannelImpl extends AbstractService implements Channel { public CallImpl(MethodDescriptor method, SerializingExecutor executor) { this.method = method; - this.executor = executor; + this.callExecutor = executor; } @Override @@ -134,8 +138,11 @@ public final class ChannelImpl extends AbstractService implements Channel { @Override public void cancel() { - Preconditions.checkState(stream != null, "Not started"); - stream.cancel(); + // Cancel is called in exception handling cases, so it may be the case that the + // stream was never successfully created. + if (stream != null) { + stream.cancel(); + } } @Override @@ -200,7 +207,7 @@ public final class ChannelImpl extends AbstractService implements Channel { private ListenableFuture dispatchCallable( final Callable> callable) { final SettableFuture ours = SettableFuture.create(); - executor.execute(new Runnable() { + callExecutor.execute(new Runnable() { @Override public void run() { try { @@ -252,7 +259,7 @@ public final class ChannelImpl extends AbstractService implements Channel { future.cancel(false); } inProcessFutures.clear(); - executor.execute(new Runnable() { + callExecutor.execute(new Runnable() { @Override public void run() { observer.onClose(status); diff --git a/stub/src/main/java/com/google/net/stubby/stub/Calls.java b/stub/src/main/java/com/google/net/stubby/stub/Calls.java index c0a125b1ba..bd6849e1b2 100644 --- a/stub/src/main/java/com/google/net/stubby/stub/Calls.java +++ b/stub/src/main/java/com/google/net/stubby/stub/Calls.java @@ -18,7 +18,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; - /** * Utility functions for processing different call idioms. We have one-to-one correspondence * between utilities in this class and the potential signatures in a generated stub class so