Skip to content

http2: fix endless loop when write an empty string

Rodrigo Muino Tomonari requested to merge github/fork/XadillaX/fix-18169 into master

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) {
  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: https://github.com/nodejs/node/issues/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

Checklist
  • make -j4 test passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

http2

Merge request reports

Loading