stream.destroy([error[, options]])


  • error <any>
  • options <Object>
    • code <bigint> | <number> 要包含在发送给对等方的 RESET_STREAMSTOP_SENDING 帧中的应用错误代码。数字会被强制转换为 BigInt。如果省略,则线编码从 error 派生(见下文)。
    • reason <string> 一个可选的人类可读原因字符串。为了与 session.close()session.destroy() 保持对称而被接受,但 不会在网络上传输——RESET_STREAMSTOP_SENDING 都不包含原因字段。提供用于应用日志记录以及 stream.onerror 回调的使用。

立即且突然地销毁流。如果提供了 error 且设置了 stream.onerror,则在销毁之前调用 onerror 回调。stream.closed Promise 会因错误而被拒绝。

🌐 Immediately and abruptly destroys the stream. If error is provided and stream.onerror is set, the onerror callback is invoked before destruction. The stream.closed promise rejects with the error.

当流被 error(或明确使用 options.code)销毁时,QUIC 堆栈会向对等方发出中止信号:

🌐 When the stream is destroyed with an error (or with an explicit options.code), the QUIC stack signals the abort to the peer:

  • 如果可写端仍然打开,将发送一个 RESET_STREAM 帧。
  • 如果可读端仍然开放(双向流,或远程发起的单向流),将发送一个 STOP_SENDING 帧。

两个帧都携带相同的线路代码,按以下优先顺序解析:

🌐 Both frames carry the same wire code, resolved with the following precedence:

  1. options.code,当明确提供时。
  2. error.errorCode,当 errorQuicError 时。
  3. 协商应用协议的“内部错误”代码(HTTP/3 的 H3_INTERNAL_ERROR (0x102),或原始 QUIC 的传输层 INTERNAL_ERROR (0x1))。

一次干净的销毁——没有 error 也没有 options.code——不会发出 RESET_STREAMSTOP_SENDING;流的现有关闭机制会处理拆卸。

🌐 A clean destroy — no error and no options.code — does not emit RESET_STREAM or STOP_SENDING; the stream's existing close machinery handles teardown.

有关可用的流中止 API 的概述,请参见 中止流

🌐 See Aborting a stream for an overview of the available stream-abort APIs.