Skip to content

Commit

Permalink
Merge branch 'master' into fix-client-hang
Browse files Browse the repository at this point in the history
  • Loading branch information
dilanSachi authored Feb 1, 2024
2 parents 6b9d9e2 + 7261ac3 commit a9d6b21
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,33 @@ function testHttp2ValidHeaderLength() returns error? {
}

//Tests the behaviour when header size is greater than the configured threshold
// TODO: Enable after fixing this issue : https://github.com/ballerina-platform/ballerina-standard-library/issues/3963
@test:Config {
enable: false
}
@test:Config {}
function testHttp2InvalidHeaderLength() returns error? {
http:Client limitClient = check new ("http://localhost:" + http2RequestLimitsTestPort3.toString(),
http2Settings = {http2PriorKnowledge: true});
http:Response response = check limitClient->get("/lowRequestHeaderLimit/invalidHeaderSize", {"X-Test": getLargeHeader()});
http:Response|http:Error response = limitClient->get("/lowRequestHeaderLimit/invalidHeaderSize", {"X-Test": getLargeHeader()});
//431 Request Header Fields Too Large
test:assertEquals(response.statusCode, 431, msg = "Found unexpected output");
if response is http:Error {
test:assertTrue(response is http:ClientError);
test:assertEquals(response.message(), "Header size exceeded max allowed size (600)");
} else {
test:assertEquals(response.statusCode, 431, msg = "Found unexpected output");
}
}

// Tests the fallback behaviour when header size is greater than the configured http2 service
// TODO: Enable after fixing this issue : https://github.com/ballerina-platform/ballerina-standard-library/issues/3963
@test:Config {
enable: false
}
@test:Config {}
function testHttp2Http2ServiceInvalidHeaderLength() returns error? {
http:Client limitClient = check new ("http://localhost:" + requestLimitsTestPort5.toString(),
http2Settings = {http2PriorKnowledge: true});
http:Response response = check limitClient->get("/http2service/invalidHeaderSize", {"X-Test": getLargeHeader()});
test:assertEquals(response.statusCode, 431, msg = "Found unexpected output");
http:Response|http:Error response = limitClient->get("/http2service/invalidHeaderSize", {"X-Test": getLargeHeader()});
if response is http:Error {
test:assertTrue(response is http:ClientError);
test:assertEquals(response.message(), "Header size exceeded max allowed size (850)");
} else {
test:assertEquals(response.statusCode, 431, msg = "Found unexpected output");
}
}

//Tests the behaviour when payload size is greater than the configured threshold
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed
- [Remove unused import from Http2StateUtil](https://github.com/ballerina-platform/ballerina-library/issues/5966)
- [Fix client getting hanged when server closes connection in the ALPN handshake](https://github.com/ballerina-platform/ballerina-library/issues/6003)
- [Fix client getting hanged when multiple requests are sent which exceed `maxHeaderSize`](https://github.com/ballerina-platform/ballerina-library/issues/6000)

## [2.10.5] - 2023-12-06

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.DefaultLastHttpContent;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaderNames;
Expand Down Expand Up @@ -320,9 +321,13 @@ public static void writeHttp2Headers(ChannelHandlerContext ctx, OutboundMsgHolde
return;
}
}

encoder.writeHeaders(ctx, streamId, http2Headers, dependencyId, weight, false, 0, endStream,
ctx.newPromise());
ChannelPromise promise = ctx.newPromise();
encoder.writeHeaders(ctx, streamId, http2Headers, dependencyId, weight, false, 0, endStream, promise);
promise.addListener((ChannelFutureListener) channelFuture -> {
if (!channelFuture.isSuccess()) {
outboundMsgHolder.getResponseFuture().notifyHttpListener(channelFuture.cause());
}
});
encoder.flowController().writePendingBytes();
ctx.flush();

Expand Down

0 comments on commit a9d6b21

Please sign in to comment.