Stream.pipeline always throw [ERR_STREAM_PREMATURE_CLOSE]
未关闭
还没有人认领这个 Issue。
stream
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.3k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
Hello.
Stream.pipeline throws error [ERR_STREAM_PREMATURE_CLOSE]: Closed prematurely, but the stream throw error new Error('destroy').
In a real application, a large file is uploaded, sometimes the server timed out the connection, and when using stream.pipeline it is not clear what error occurred, ERR_STREAM_PREMATURE_CLOSE is always returned.
Version: 15.5.0
Platform: Ubuntu 20.10 x64
/* eslint-disable */
import http from 'https';
import { createWriteStream } from 'fs';
import { pipeline } from 'stream/promises';
const httpRequest = url => new Promise(resolve => http.get(url, res => resolve(res)));
const FILENAME_TMP = './1.tmp'
const linkFile = 'https://nodejs.org/dist/v15.5.0/node-v15.5.0-linux-x64.tar.xz';
const downloadStream = await httpRequest(linkFile, { responseType: 'stream' });
// view error
downloadStream.on('error', err => console.log('onError', err));
// break download
setTimeout(() => downloadStream.destroy(new Error('destroy')), 1000);
try {
await pipeline(
downloadStream,
createWriteStream(FILENAME_TMP)
);
console.log('Done');
} catch (err) {
console.log('onPipeline', err);
}
onError Error: destroy
at Timeout._onTimeout (file:///home/user/Project/parser/3.js:17:41)
at listOnTimeout (node:internal/timers:556:17)
at processTimers (node:internal/timers:499:7)
onPipeline Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
at new NodeError (node:internal/errors:278:15)
at IncomingMessage.onclose (node:internal/streams/end-of-stream:117:38)
at IncomingMessage.emit (node:events:376:20)
at IncomingMessage._destroy (node:_http_incoming:169:10)
at _destroy (node:internal/streams/destroy:67:23)
at IncomingMessage.destroy (node:internal/streams/destroy:59:5)
at Timeout._onTimeout (file:///home/user/Project/parser/3.js:17:33)
at listOnTimeout (node:internal/timers:556:17)
at processTimers (node:internal/timers:499:7) {
code: 'ERR_STREAM_PREMATURE_CLOSE'
}
Thank's
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
以提供的 Node.js 15.5.0 复现为起点;检查 stream/promises 以及 stack trace 中显示的 end-of-stream 和 destroy 路径。比较源 stream 的 destroy 错误与 pipeline 的 ERR_STREAM_PREMATURE_CLOSE 结果,并将 done 定义为回归测试或有文档记录的行为,以明确预期的错误传播。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, nodejs
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100