diff options
author | James M Snell <jasnell@gmail.com> | 2018-01-01 17:51:34 -0800 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-01-03 14:45:57 -0800 |
commit | 651ce28be949e0b435b4beb7e61547e31414c4f2 (patch) | |
tree | 0126b2b671ad7d8b3dff3e77a6bebd972b88ed7c /src/node_http2.cc | |
parent | efdadcc193dc1a2b2121fecf1a3ef24d5c35b564 (diff) | |
download | android-node-v8-651ce28be949e0b435b4beb7e61547e31414c4f2.tar.gz android-node-v8-651ce28be949e0b435b4beb7e61547e31414c4f2.tar.bz2 android-node-v8-651ce28be949e0b435b4beb7e61547e31414c4f2.zip |
http2: properly handle already closed stream error
PR-URL: https://github.com/nodejs/node/pull/17942
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/node_http2.cc')
-rw-r--r-- | src/node_http2.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/node_http2.cc b/src/node_http2.cc index d37e97b696..7bdd520eff 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -457,6 +457,8 @@ Http2Session::Callbacks::Callbacks(bool kHasGetPaddingCallback) { callbacks, OnNghttpError); nghttp2_session_callbacks_set_send_data_callback( callbacks, OnSendData); + nghttp2_session_callbacks_set_on_invalid_frame_recv_callback( + callbacks, OnInvalidFrame); if (kHasGetPaddingCallback) { nghttp2_session_callbacks_set_select_padding_callback( @@ -880,6 +882,31 @@ inline int Http2Session::OnFrameReceive(nghttp2_session* handle, return 0; } +inline int Http2Session::OnInvalidFrame(nghttp2_session* handle, + const nghttp2_frame *frame, + int lib_error_code, + void* user_data) { + Http2Session* session = static_cast<Http2Session*>(user_data); + + DEBUG_HTTP2SESSION2(session, "invalid frame received, code: %d", + lib_error_code); + + // If the error is fatal or if error code is ERR_STREAM_CLOSED... emit error + if (nghttp2_is_fatal(lib_error_code) || + lib_error_code == NGHTTP2_ERR_STREAM_CLOSED) { + Environment* env = session->env(); + Isolate* isolate = env->isolate(); + HandleScope scope(isolate); + Local<Context> context = env->context(); + Context::Scope context_scope(context); + + Local<Value> argv[1] = { + Integer::New(isolate, lib_error_code), + }; + session->MakeCallback(env->error_string(), arraysize(argv), argv); + } + return 0; +} // If nghttp2 is unable to send a queued up frame, it will call this callback // to let us know. If the failure occurred because we are in the process of |