如果客户端关闭会话,nodejs v8.11.3在带有TLS的http2中中止

时间:2018-09-17 20:57:35

标签: node.js https http2

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

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帧?

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

注意:问题并非总是会发生,但是在更复杂的测试场景中可以重现。

查询解决方案

查看答案。

1 个答案:

答案 0 :(得分:0)

我做了一个古怪的事情,通过猴子修补“走走”来避开问题,并引入了一个明确的检查插座是否已经关闭。 TypeScript代码:

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)