Skip to content

Commit fc71f65

Browse files
author
oleksiys
committed
[master] + minor updates
1 parent e84ee12 commit fc71f65

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,7 @@ private static boolean isRedirectAllowed(final HttpTxContext ctx) {
379379
private static HttpTxContext cleanup(final FilterChainContext ctx) {
380380

381381
final Connection c = ctx.getConnection();
382-
final HttpTxContext context = HttpTxContext.get(ctx);
383-
HttpTxContext.remove(ctx, context);
382+
final HttpTxContext context = HttpTxContext.remove(ctx);
384383
if (!Utils.isSpdyConnection(c) && !Utils.isIgnored(c)) {
385384
final ConnectionManager manager = context.getProvider().getConnectionManager();
386385
//if (!manager.canReturnConnection(c)) {

providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public final class HttpTxContext {
6969
private final CloseListener listener = new CloseListener<Closeable, CloseType>() {
7070
@Override
7171
public void onClosed(Closeable closeable, CloseType type) throws IOException {
72-
if (isGracefullyFinishResponseOnClose()) {
72+
if (responseStatus != null && // responseStatus==null if request wasn't even sent
73+
isGracefullyFinishResponseOnClose()) {
7374
// Connection was closed.
7475
// This event is fired only for responses, which don't have
7576
// associated transfer-encoding or content-length.
@@ -107,10 +108,14 @@ public static void set(final FilterChainContext ctx, final HttpTxContext httpTxC
107108
REQUEST_STATE_ATTR.set(httpContext, httpTxContext);
108109
}
109110

110-
public static void remove(final FilterChainContext ctx, final HttpTxContext httpTxContext) {
111-
HttpContext httpContext = HttpContext.get(ctx);
112-
httpContext.getCloseable().removeCloseListener(httpTxContext.listener);
113-
REQUEST_STATE_ATTR.remove(ctx);
111+
public static HttpTxContext remove(final FilterChainContext ctx) {
112+
final HttpContext httpContext = HttpContext.get(ctx);
113+
final HttpTxContext httpTxContext = REQUEST_STATE_ATTR.remove(httpContext);
114+
if (httpTxContext != null) {
115+
httpContext.getCloseable().removeCloseListener(httpTxContext.listener);
116+
}
117+
118+
return httpTxContext;
114119
}
115120

116121
public static HttpTxContext get(FilterChainContext ctx) {

0 commit comments

Comments
 (0)