简体   繁体   English

快速请求中止

[英]Express Request Aborted

I am using Express.js to implement my backend.我正在使用 Express.js 来实现我的后端。 I often got the error.我经常得到错误。 I don't know why.我不知道为什么。

I put the source code to AWS Elastic Beanstalk and set the ELB.我将源代码放入 AWS Elastic Beanstalk 并设置 ELB。 If this error triggers more times, it will make all users cannot connect to the server.如果此错误触发次数过多,将导致所有用户无法连接到服务器。 I always restart the Beanstalk instance to fix this problem.我总是重启 Beanstalk 实例来解决这个问题。 But I don't know when will trigger this error.但我不知道什么时候会触发这个错误。 So please help me to fix it.所以请帮我解决它。

Thanks a lot.非常感谢。

{     
    BadRequestError: request aborted
    at IncomingMessage.onAborted (/var/app/current/node_modules/raw-body/index.js:231:10)
    at IncomingMessage.emit (events.js:189:13)
    at IncomingMessage.EventEmitter.emit (domain.js:441:20)
    at abortIncoming (_http_server.js:449:9)
    at socketOnClose (_http_server.js:442:3)
    at Socket.emit (events.js:194:15)
    at Socket.EventEmitter.emit (domain.js:441:20)
    at TCP._handle.close (net.js:600:12)
    message: 'request aborted',
    code: 'ECONNABORTED',
    expected: 18774,
    length: 18774,
    received: 0,
    type: 'request.aborted',
    expose: true,
    statusCode: 400,
    status: 400 
} 
app.use((req, res, next) => {
  logger.info(`marker 1, ${req.header('Content-Type')}, ${req.header('Content-Length')}`)
  next()
})

app.use(express.json({
  type: 'application/json',
  limit: '50mb',
  strict: false,
  verify: (req, res, buf, encoding) => {
    logger.info(`marker 2, ${req.body.length}`)
  }
}));
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

// catch 404 and forward to error handler
app.use(function(e, req, res, next) {
  // set locals, only providing error in development
  logger.error(e);
  const err = SQError.wrapError(e);
  
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.httpCode || 500);
  var response = req.body.params ? req.body : {};
  logger.error(err, req.app.get('env') === 'development' ? {method: req.body.method || ""} : {});
  if(response.params) 
    response.params.error = err.toJson()
  else 
    response = { error : err.toJson() }
  res.json(response);
});

This error will occur when the request is aborted by the client before reading the body has finished.当请求在读取正文完成之前被客户端中止时,将发生此错误。 The status property is set to 400 and type property is set to 'request.aborted'. status 属性设置为 400,type 属性设置为“request.aborted”。 Please put the setup express code!请把设置快递代码!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM