Skip to content

Instantly share code, notes, and snippets.

@vietj
Created March 16, 2024 11:35
Show Gist options
  • Save vietj/f558b8ea81ec6505f1e9a6ca283c9ae3 to your computer and use it in GitHub Desktop.
Save vietj/f558b8ea81ec6505f1e9a6ca283c9ae3 to your computer and use it in GitHub Desktop.
public class Reproducer {
HttpServer server = vertx.createHttpServer();
server.requestHandler(req -> {
req.setExpectMultipart(true);
req.endHandler(v -> {
System.out.println(req.formAttributes().size());
req.response().end();
});
});
server.listen(8080, "localhost").toCompletionStage().toCompletableFuture().get();
HttpClient client = vertx.createHttpClient();
client.request(new RequestOptions()
.setMethod(HttpMethod.POST)
.setHost("localhost")
.setPort(8080)).onComplete(onSuccess(req -> {
req.setChunked(true);
req.putHeader("content-type", "application/x-www-form-urlencoded");
req.write("framework=vertx");
send(req, 32_000_000
);
req
.response()
.compose(resp -> resp.body())
.onComplete(onSuccess(v -> testComplete()));
}));
vertx.setPeriodic(1000, id -> {
System.out.println(Runtime.getRuntime().freeMemory());
});
await();
}
private int seq = 0;
private Buffer buffer = Buffer.buffer(TestUtils.randomAlphaString(2048));
private void send(HttpClientRequest req, int amount) {
int num = Math.min(64, amount);
for (int i = 0;i < num;i++) {
req.write("&item-" + seq++ + "=");
req.write(buffer);
}
int remaining = amount - num;
if (req.writeQueueFull()) {
req.drainHandler(v -> {
send(req, remaining);
});
return;
}
if (remaining == 0) {
req.end();
} else {
vertx.runOnContext(v -> send(req, remaining));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment