Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information