【问题标题】:nodejs v8.11.3 aborts in http2 with TLS if client closes session如果客户端关闭会话,nodejs v8.11.3 使用 TLS 在 http2 中中止
【发布时间】:2019-02-21 20:12:12
【问题描述】:

我遇到了 nodejs v8.11.3 的问题。我正在使用带有 TLS (https) 的 http2,并且当客户端关闭会话时服务器中止。这是错误:

HTTP2 31334: Http2Session server: socket closed
HTTP2 31334: Http2Session server: marking session closed
HTTP2 31334: Http2Session server: submitting goaway
node[31334]: ../src/tls_wrap.cc:604:virtual int node::TLSWrap::DoWrite(node::WriteWrap*, uv_buf_t*, size_t, uv_stream_t*): Assertion `(ssl_) != (nullptr)' failed.
 1: node::Abort() [node]
 2: 0x8c25db [node]
 3: node::TLSWrap::DoWrite(node::WriteWrap*, uv_buf_t*, unsigned long, uv_stream_s*) [node]
 4: node::http2::Http2Session::SendPendingData() [node]
 5: 0x90e769 [node]
 6: node::Environment::RunAndClearNativeImmediates() [node]
 7: node::Environment::CheckImmediate(uv_check_s*) [node]
 8: 0x141a4ac [node]
 9: uv_run [node]
10: node::Start(uv_loop_s*, int, char const* const*, int, char const* const*) [node]
11: node::Start(int, char**) [node]
12: __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
13: 0x89b1b1 [node]
Aborted (core dumped)

让我感到困惑的是为什么尽管套接字已经关闭,但服务器仍然发出 GOAWAY 帧?

有人知道避免这个问题的一些怪癖吗?

注意:问题并不总是发生,但可以作为更复杂的测试场景的一部分重现。

怪异解决方案

查看答案。

【问题讨论】:

    标签: node.js https http2


    【解决方案1】:

    我做了一个怪癖来规避这个问题,通过猴子补丁“goaway”并引入显式检查套接字是否已关闭。打字稿代码:

    const GOAWAY = Symbol();
    
    interface ExtServerHttp2Session extends http2.ServerHttp2Session {
      [GOAWAY]?: (code?: number, lastStreamID?: number, opaqueData?: Buffer | DataView /*| TypedArray*/) => void;
    }
    
    function patchedGoaway(
      this: ExtServerHttp2Session,
      code?: number,
      lastStreamID?: number,
      opaqueData?: Buffer | DataView /*| TypedArray*/
    ): void {
      if (!this.closed) {
        this[GOAWAY]!(code, lastStreamID, opaqueData);
      }
    }
    
    function monkeyPatch(session: http2.Http2Session) {
      const extSession = session as ExtServerHttp2Session;
      if (!extSession[GOAWAY]) {
        extSession[GOAWAY] = extSession.goaway;
        extSession.goaway = patchedGoaway;
      }
    }
    

    现在在处理新流时,您调用monkeyPatch(stream.session)。

    【讨论】:

      猜你喜欢
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      • 2020-02-10
      • 2021-09-28
      相关资源
      最近更新 更多