我无法找到阻止客户接收我的回复的内容。所有代码都工作,命令行显示响应被发送但客户端永远不会得到它。我可以使用req.destroy或Connection close标头强制它。有什么方法可以看到阻止它的是什么?
我将管道请求放入busboy,然后将文件从busboy传送到流中以验证文件。问题是,当这个完成后,我需要将流发送到一个函数。这基本上就是我现在正在做的事情,但是当出现错误时它会挂起。我还必须提高highWaterMark,因为我没有消耗它。
validateCSV
.on('finish', () => {
datasetService.import(validateCSV, dataset, (er) => {
....
})
}
.on('error', (err) => {
//The res never sends
res.status(500).json(err).end();
}
除非我从Transform流中发出错误,否则这样可以正常工作。我是否需要在数据事件中使用它?我应该在使用函数之前缓冲流吗?
这是错误后流的样子:
ValidateCSV {
_readableState:
ReadableState {
objectMode: true,
highWaterMark: 1000000,
buffer: [],
length: 0,
pipes: null,
pipesCount: 0,
flowing: null,
ended: false,
endEmitted: false,
reading: false,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events:
{ end: { [Function: g] listener: [Function: onend] },
prefinish: { [Function: g] listener: [Function] },
finish: [ [Function] ],
error: [ [Function] ] },
_eventsCount: 4,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: true,
highWaterMark: 1000000,
needDrain: false,
ending: false,
ended: false,
finished: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 1,
writing: true,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function],
writecb: [Function: nop],
writelen: 1,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 1,
prefinished: false,
errorEmitted: false },
writable: true,
allowHalfOpen: true,
_transformState:
TransformState {
afterTransform: [Function],
needTransfor`enter code here`m: false,
transforming: true,
writecb: [Function],
writechunk: <Buffer 50 6f 6c 69 63 79 54 79 70 65 2c 4e 61 6d 65 2c 50 72 6f 70 41 64 64 72 65 73 73 32 2c 50 72 6f 70 43 69 74 79 2c 50 72 6f 70 5a 69 70 2c 50 6f 6c 69 ... >,
writeencoding: 'buffer' } }