0

我找不到阻止客户接收我的回复的原因。所有代码都有效,命令行显示正在发送响应,但客户端从未收到它。我可以使用 req.destroy 或 Connection 关闭标头强制它。有什么办法可以查看是什么阻止了它?

我将 req 管道传输到 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' } }
4

0 回答 0