Skip to content
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "Netty NIO HTTP Client",
"contributor": "",
"description": "Fix a bug where, if validation of of the amount of expected data to be received (HTTP `Content-Length`) fails, the connection would be left dangling, consuming a connection from the pool until the client is shut down."
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ public void onComplete() {
}
} catch (IOException e) {
notifyError(e);
runAndLogError(channelContext.channel(), () -> "Could not release channel back to the pool",
() -> closeAndRelease(channelContext));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,56 @@ public void onComplete() {
}
}

@Test
public void contentLengthValidationFails_closesAndReleasesConnection() {
channel.attr(ChannelAttributeKey.RESPONSE_CONTENT_LENGTH).set(1L);
channel.attr(ChannelAttributeKey.RESPONSE_DATA_READ).set(0L);

Publisher<HttpContent> publisher = subscriber -> subscriber.onSubscribe(new Subscription() {
@Override
public void request(long l) {
subscriber.onComplete();
}

@Override
public void cancel() {
}
});

DefaultStreamedHttpResponse streamedResponse = new DefaultStreamedHttpResponse(HttpVersion.HTTP_1_1,
HttpResponseStatus.OK, publisher);

Subscriber<ByteBuffer> subscriber = new Subscriber<ByteBuffer>() {
private Subscription subscription;

@Override
public void onSubscribe(Subscription subscription) {
this.subscription = subscription;
subscription.request(Long.MAX_VALUE);
}

@Override
public void onNext(ByteBuffer byteBuffer) {
}

@Override
public void onError(Throwable throwable) {
}

@Override
public void onComplete() {
}
};

ResponseHandler.PublisherAdapter publisherAdapter = new ResponseHandler.PublisherAdapter(streamedResponse, ctx,
requestContext, executeFuture);

publisherAdapter.subscribe(subscriber);

verify(ctx).close();
verify(channelPool).release(channel);
}

static final class TestSubscriber implements Subscriber<ByteBuffer> {

private Subscription subscription;
Expand Down