Nest.js 在一定时间后挂起,没有任何日志

问题描述 投票:0回答:1

我们目前使用 Nest.JS 作为我们的后端解决方案已经将近 2 年了。它工作得非常好,直到上周才给我们带来任何大问题。正如标题所描述的,它突然挂断,没有返回任何类型的日志。我们将它与 pm2 结合使用,它托管在运行 ubuntu 的 aws t3.medium 机器上。

我们在他们的文档中使用了 nest.js 提供的异常过滤器:

import {
  ExceptionFilter,
  Catch,
  ArgumentsHost,
  HttpException,
  HttpStatus,
} from '@nestjs/common';
import { HttpAdapterHost } from '@nestjs/core';

@Catch()
export class AllExceptionsFilter implements ExceptionFilter {
  constructor(private readonly httpAdapterHost: HttpAdapterHost) {}

  catch(exception: unknown, host: ArgumentsHost): void {
    // In certain situations `httpAdapter` might not be available in the
    // constructor method, thus we should resolve it here.
    const { httpAdapter } = this.httpAdapterHost;

    const ctx = host.switchToHttp();

    const httpStatus =
      exception instanceof HttpException
        ? exception.getStatus()
        : HttpStatus.INTERNAL_SERVER_ERROR;

    const responseBody = {
      statusCode: httpStatus,
      timestamp: new Date().toISOString(),
      path: httpAdapter.getRequestUrl(ctx.getRequest()),
    };

    httpAdapter.reply(ctx.getResponse(), responseBody, httpStatus);
  }
}

是否可以记录应用程序关闭的原因以及给我们带来问题的具体路径?这样修复起来会更容易。

编辑:我们也订阅了哨兵,但这些日志也没有到达它。

amazon-web-services nestjs pm2
1个回答
0
投票

这个有更新吗?我也遇到了这个问题

我的视角:

  • k8s 在 aws 上管理
  • 与节点和捆绑应用程序一起运行的 Pod
  • 健康端点总是返回 200 ok

发生什么事了? 一段时间后,暂时不确定,或者在重负载下,看起来调用挂起以接收响应,但我们没有日志,也没有异常,也没有注册任何调用。即使在客户端因超时而断开连接后,也没有日志或任何类型的反馈。

我经历过重负载操作系统流量(我认为是节点 js 卡住了);但最近它发生在没有任何流量的情况下。

重启进程(pod)暂时解决问题。

不认为它应该与this有关但事实是它发生在使用nestjs rest calls的微服务之间

谢谢

© www.soinside.com 2019 - 2024. All rights reserved.