private void doCancel() {
        final Subscription upstreamSubscription = this.upstreamSubscription;
        if (upstreamSubscription != null) {
            try {
                upstreamSubscription.cancel();
            } finally {
                // Clear the subscriber when we become sure that the upstream will not produce events anymore.
                final StreamMessage<T> upstream = this.upstream;
                assert upstream != null;
                final SubscriptionImpl downstreamSubscription = this.downstreamSubscription;
                assert downstreamSubscription != null;
                if (upstream.isComplete()) {
                    downstreamSubscription.clearSubscriber();
                } else {
                    upstream.whenComplete().handle((u1, u2) -> {
                        downstreamSubscription.clearSubscriber();
                        return null;
                    });
                }
            }
        } else {
            abort(CancelledSubscriptionException.get());
        }
    }
Closes the deferred stream without setting a delegate.

@throws IllegalStateException if the delegate has been set already or
                              if {@link #close()} or {@link #close(Throwable)} was called already.
core/src/main/java/com/linecorp/armeria/common/stream/DeferredStreamMessage.java