Notify connect promise of ProxyHandler after codecs are removed

Motivation:

We need to notify the promise after the codecs are removed to allow writing from the listener and ensure we not try to do any encoding anymore. If we not do we will end up with corrupt data.

Modifications:

Notify promise after codecs are removed.

Result:

Fixes [#6671].
This commit is contained in:
Norman Maurer 2017-04-26 08:17:55 +02:00
parent 57d3393527
commit 8b13d9656a

View File

@ -283,11 +283,9 @@ public abstract class ProxyHandler extends ChannelDuplexHandler {
private void setConnectSuccess() {
finished = true;
if (connectTimeoutFuture != null) {
connectTimeoutFuture.cancel(false);
}
cancelConnectTimeoutFuture();
if (connectPromise.trySuccess(ctx.channel())) {
if (!connectPromise.isDone()) {
boolean removedCodec = true;
removedCodec &= safeRemoveEncoder();
@ -303,13 +301,12 @@ public abstract class ProxyHandler extends ChannelDuplexHandler {
if (flushedPrematurely) {
ctx.flush();
}
connectPromise.trySuccess(ctx.channel());
} else {
// We are at inconsistent state because we failed to remove all codec handlers.
Exception cause = new ProxyConnectException(
"failed to remove all codec handlers added by the proxy handler; bug?");
failPendingWrites(cause);
ctx.fireExceptionCaught(cause);
ctx.close();
failPendingWritesAndClose(cause);
}
}
}
@ -338,22 +335,32 @@ public abstract class ProxyHandler extends ChannelDuplexHandler {
private void setConnectFailure(Throwable cause) {
finished = true;
if (connectTimeoutFuture != null) {
connectTimeoutFuture.cancel(false);
}
cancelConnectTimeoutFuture();
if (!(cause instanceof ProxyConnectException)) {
cause = new ProxyConnectException(
exceptionMessage(cause.toString()), cause);
}
if (!connectPromise.isDone()) {
if (!(cause instanceof ProxyConnectException)) {
cause = new ProxyConnectException(
exceptionMessage(cause.toString()), cause);
}
if (connectPromise.tryFailure(cause)) {
safeRemoveDecoder();
safeRemoveEncoder();
failPendingWritesAndClose(cause);
}
}
failPendingWrites(cause);
ctx.fireExceptionCaught(cause);
ctx.close();
private void failPendingWritesAndClose(Throwable cause) {
failPendingWrites(cause);
connectPromise.tryFailure(cause);
ctx.fireExceptionCaught(cause);
ctx.close();
}
private void cancelConnectTimeoutFuture() {
if (connectTimeoutFuture != null) {
connectTimeoutFuture.cancel(false);
connectTimeoutFuture = null;
}
}