Skip to content

Commit

Permalink
Reverse order of closing and completing the promise
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfjack committed Feb 22, 2019
1 parent 800e7f2 commit d670b7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.auth.Credentials;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
Expand Down Expand Up @@ -164,41 +165,31 @@ private HttpRequest buildRequest(String path, String host) {
}

private void succeedAndReset(ChannelHandlerContext ctx) {
try {
if (keepAlive) {
succeedAndResetUserPromise();
} finally {
reset(ctx);
} else {
reset(ctx).addListener((f) -> succeedAndResetUserPromise());
}
}

@SuppressWarnings("FutureReturnValueIgnored")
private void failAndClose(Throwable t, ChannelHandlerContext ctx) {
try {
failAndResetUserPromise(t);
} finally {
ctx.close();
}
ctx.close().addListener((f) -> failAndResetUserPromise(t));
}

private void failAndReset(Throwable t, ChannelHandlerContext ctx) {
try {
if (keepAlive) {
failAndResetUserPromise(t);
} finally {
reset(ctx);
} else {
reset(ctx).addListener((f) -> failAndResetUserPromise(t));
}
}

@SuppressWarnings("FutureReturnValueIgnored")
private void reset(ChannelHandlerContext ctx) {
try {
if (!keepAlive) {
ctx.close();
}
} finally {
out = null;
keepAlive = HttpVersion.HTTP_1_1.isKeepAliveDefault();
downloadSucceeded = false;
response = null;
}
private ChannelFuture reset(ChannelHandlerContext ctx) {
out = null;
keepAlive = HttpVersion.HTTP_1_1.isKeepAliveDefault();
downloadSucceeded = false;
response = null;
return ctx.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ private HttpChunkedInput buildBody(UploadCommand msg) {

@SuppressWarnings("FutureReturnValueIgnored")
private void failAndClose(Throwable t, ChannelHandlerContext ctx) {
try {
failAndResetUserPromise(t);
} finally {
ctx.close();
}
ctx.close().addListener((f) -> failAndResetUserPromise(t));
}
}

0 comments on commit d670b7c

Please sign in to comment.