Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web Client post request may not complete if connection is closed during upload #2562

Closed
tsegismont opened this issue Jan 31, 2024 · 2 comments
Assignees
Milestone

Comments

@tsegismont
Copy link
Contributor

The bug can be reproduced with this:

    int concurrency = 2;

    Vertx vertx = Vertx.vertx();

    WebClient webClient = WebClient.wrap(vertx.createHttpClient(new PoolOptions().setHttp1MaxSize(1)));

    String largeString = TestUtils.randomAlphaString(1024 * 1024);

    MultiMap form = MultiMap.caseInsensitiveMultiMap();
    form.add("foo", largeString);

    CountDownLatch latch = new CountDownLatch(concurrency);

    vertx.runOnContext(v -> {
      for (int i = 0; i < concurrency; i++) {
        final int iFinal = i;
        Future<HttpResponse<Buffer>> future = webClient.postAbs("http://www.google.com").sendForm(form);
        future.onComplete(ar -> {
          System.out.println("iFinal = " + iFinal);
          if (ar.succeeded()) {
            System.out.println("Success: " + ar.result().statusCode());
          } else {
            System.out.println("Failure");
            ar.cause().printStackTrace(System.out);
          }
          latch.countDown();
        });
      }
    });

    try {
      latch.await();
    } catch (Exception e) {
      e.printStackTrace(System.out);
    } finally {
      vertx.close();
    }

This program should terminate printing Success: 413 twice.

Instead, it never terminates and prints:

iFinal = 0
Success: 413
Jan 31, 2024 3:00:36 PM io.vertx.core.http.impl.HttpClientRequestImpl
SEVERE: Stream reset: 0
@tsegismont tsegismont added this to the 4.5.3 milestone Jan 31, 2024
@vietj vietj modified the milestones: 4.5.3, 4.5.4 Feb 6, 2024
@vietj vietj modified the milestones: 4.5.4, 4.5.5 Feb 22, 2024
@vietj vietj self-assigned this Mar 13, 2024
@vietj
Copy link
Contributor

vietj commented Mar 13, 2024

This happens when the client receives a response that closes the connection and has not yet finished sending the request. Since the request is not yet fully send (due to back-pressure) by the client the HttpClient will release the connection which is reused for the second request, since the initial request is not finished the second request allocation is created and not completed (pretty much like with pipelining) when the connection processed the connection close, the second stream allocation request is not failed.

eclipse-vertx/vert.x#5151 fixes this in a way that when the request is not yet sent, the connection is not recycled until the request is ended. In addition the pipelining case has been addressed here eclipse-vertx/vert.x#5152

@vietj vietj closed this as completed Mar 13, 2024
@tsegismont
Copy link
Contributor Author

Thank you @vietj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants