我们目前使用 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);
}
}
是否可以记录应用程序关闭的原因以及给我们带来问题的具体路径?这样修复起来会更容易。
编辑:我们也订阅了哨兵,但这些日志也没有到达它。
这个有更新吗?我也遇到了这个问题
我的视角:
发生什么事了? 一段时间后,暂时不确定,或者在重负载下,看起来调用挂起以接收响应,但我们没有日志,也没有异常,也没有注册任何调用。即使在客户端因超时而断开连接后,也没有日志或任何类型的反馈。
我经历过重负载操作系统流量(我认为是节点 js 卡住了);但最近它发生在没有任何流量的情况下。
重启进程(pod)暂时解决问题。
不认为它应该与this有关但事实是它发生在使用nestjs rest calls的微服务之间
谢谢