Skip to content

Commit

Permalink
Remove close-on-cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
idelpivnitskiy committed Apr 8, 2020
1 parent cfd0117 commit 57e470b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.servicetalk.client.api.DelegatingConnectionFactory;
import io.servicetalk.concurrent.SingleSource;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.concurrent.api.SingleTerminalSignalConsumer;
import io.servicetalk.http.api.FilterableStreamingHttpConnection;
import io.servicetalk.http.api.HttpExecutionStrategy;
import io.servicetalk.http.api.HttpExecutionStrategyInfluencer;
Expand All @@ -33,8 +32,6 @@
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.ssl.SslHandshakeCompletionEvent;

import javax.annotation.Nullable;

import static io.servicetalk.concurrent.api.Processors.newSingleProcessor;
import static io.servicetalk.concurrent.api.Single.failed;
import static io.servicetalk.concurrent.api.SourceAdapters.fromSource;
Expand Down Expand Up @@ -78,26 +75,8 @@ public Single<C> newConnection(final ResolvedAddress resolvedAddress) {
// connection filters we use the default strategy which should offload everything to be safe.
return c.request(defaultStrategy(), c.connect(connectAddress).addHeader(CONTENT_LENGTH, ZERO))
.flatMap(response -> handleConnectResponse(c, response))
// Close recently created connection in case of any error while it connects to the proxy
// or cancellation:
.recoverWith(t -> c.closeAsync().concat(failed(t)))
// Use afterFinally to prevent handling cancel event after termination:
.afterFinally(new SingleTerminalSignalConsumer<C>() {
@Override
public void cancel() {
c.closeAsync().subscribe();
}

@Override
public void onSuccess(@Nullable final C result) {
// noop
}

@Override
public void onError(final Throwable throwable) {
// noop
}
});
// Close recently created connection in case of any error while it connects to the proxy:
.recoverWith(t -> c.closeAsync().concat(failed(t)));
} catch (Throwable t) {
return c.closeAsync().concat(failed(t));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.ssl.SslHandshakeCompletionEvent;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.stubbing.Answer;

Expand Down Expand Up @@ -255,6 +256,7 @@ public void sslHandshakeFailure() {
}

@Test
@Ignore("https://github.com/apple/servicetalk/issues/1010")
public void cancelledBeforeSslHandshakeCompletionEvent() {
ChannelPipeline pipeline = configurePipeline(null); // Do not generate any SslHandshakeCompletionEvent

Expand Down

0 comments on commit 57e470b

Please sign in to comment.