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

Packet lost in Http1xOrHttp2Handler #2007

Closed
purplefox opened this issue Jun 2, 2017 · 0 comments
Closed

Packet lost in Http1xOrHttp2Handler #2007

purplefox opened this issue Jun 2, 2017 · 0 comments
Assignees

Comments

@purplefox
Copy link
Contributor

purplefox commented Jun 2, 2017

If we send an http request beginning with "P" (i.e. a POST, PATCH or PUT) split across two packets where the first packet has data length of 1 byte and the second packet contains the rest of the request, then the Http1xOrHttp2Handler reads the 1 byte packet, and then throws it away.

When the second packet comes in it does not aggregate the 1 byte that it previously read with the second packet, resulting in the method being received as "OST", "ATCH", or "UT".

A workaround is to disable the Http1xOrHttp2Handler with:
System.setProperty("vertx.disableH2c", "true");

Reproducer:

  @Test
  public void test1BytePost() throws Exception {

    // The test will pass if we disable the http2 decoder:
    //  System.setProperty("vertx.disableH2c", "true");


    CountDownLatch latch1 = new CountDownLatch(1);
    server.requestHandler(req -> {
      assertEquals("POST", req.rawMethod());
      latch1.countDown();
    });

    String fullRequest = "POST /whatever HTTP/1.1\r\n\r\n";

    CountDownLatch latch2 = new CountDownLatch(1);
    server.listen(onSuccess(s -> {
      latch2.countDown();
    }));
    latch2.await();

    try (Socket sock = new Socket("localhost", 8080)) {

      byte[] rawData = fullRequest.getBytes();
      System.out.println("total Len = " + rawData.length);

      // send 1 byte packet
      sock.getOutputStream().write(rawData, 0, 1);
      sock.getOutputStream().flush();

      Thread.sleep(750);

      // send the rest
      sock.getOutputStream().write(rawData, 1, rawData.length - 1);
      sock.getOutputStream().flush();
    }

    latch1.await();

  }
@purplefox purplefox changed the title Bug in Http1xOrHttp2Handler for 1 byte packet Packet lost in Http1xOrHttp2Handler Jun 2, 2017
@vietj vietj self-assigned this Jun 4, 2017
@vietj vietj added the to review label Jun 4, 2017
tsegismont added a commit that referenced this issue Jun 6, 2017
Packet lost in Http1xOrHttp2Handler - fixes #2007
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants