Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

WIP:Read all before closing client connection #74

Open
wants to merge 1 commit into
base: vgs-edition
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.channel.udt.nio.NioUdtProvider;
import io.netty.handler.codec.http.FullHttpResponse;
Expand Down Expand Up @@ -92,6 +93,8 @@ public class ProxyToServerConnection extends ProxyConnection<HttpResponse> {
private volatile ChainedProxy chainedProxy;
private final Queue<ChainedProxy> availableChainedProxies;

private ChannelPromise lastUpstreamReadProcessed;

/**
* The filters to apply to response/chunks received from server.
*/
Expand Down Expand Up @@ -262,6 +265,8 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
} else {
ReferenceCountUtil.retain(httpResponse);

lastUpstreamReadProcessed = channel.newPromise();

proxyServer.getMessageProcessingExecutor()
.execute(() -> {
try {
Expand All @@ -274,6 +279,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
exceptionCaught(ctx, e);
} finally {
ReferenceCountUtil.release(httpResponse);
lastUpstreamReadProcessed.setSuccess();
}
});
}
Expand Down Expand Up @@ -468,7 +474,16 @@ protected void disconnected() {
LOG.error("Unable to record connectionFailed", e);
}
}
clientConnection.serverDisconnected(this);
final ProxyToServerConnection serverConnection = this;

if (lastUpstreamReadProcessed == null) {
clientConnection.serverDisconnected(serverConnection);
} else {
lastUpstreamReadProcessed.addListener(future ->
clientConnection.serverDisconnected(serverConnection));
}


}

@Override
Expand Down