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

http2: fix endless loop when write an empty string #18673

Closed
wants to merge 2 commits into from

Commits on Feb 11, 2018

  1. http2: fix endless loop when write an empty string

    If we do `req.write("")` (an empty string) on Http2Stream, the gather
    logic will be messed up:
    
    ```
    while ((src_length = nghttp2_session_mem_send(session_, &src)) > 0) {
      printf("write\n");
      DEBUG_HTTP2SESSION2(this, "nghttp2 has %d bytes to send", src_length);
      CopyDataIntoOutgoing(src, src_length);
    }
    ```
    
    The logic above is in function `Http2Session::SendPendingData` under
    src/node_http2.cc. This `while` will be endless when an empty string is
    inside because `src_length` will always be 9.
    
    And then the main event loop thread will be blocked and the memory used
    will be larger and larger.
    
    This pull request is to ignore empty string or buffer in `_write()` and
    `_writev()` of Http2Stream.
    
    Fixes: nodejs#18169
    Refs: https://github.com/nodejs/node/blob/v9.5.0/src/node_http2.cc#L1481-L1484
    Refs: https://github.com/nodejs/node/blob/v9.5.0/lib/_http_outgoing.js#L659-L661
    XadillaX committed Feb 11, 2018
    Configuration menu
    Copy the full SHA
    5ab3255 View commit details
    Browse the repository at this point in the history
  2. add test cases

    XadillaX committed Feb 11, 2018
    Configuration menu
    Copy the full SHA
    83fb36a View commit details
    Browse the repository at this point in the history