-
Notifications
You must be signed in to change notification settings - Fork 224
-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nest.js ECONNREFUSED after an uncaught exception #2359
Comments
@abreu-gyant Thank you very much for the repro code! Apologies for the delay in responding. I am able to reproduce what you are describing. However, I believe the APM agent is operating correctly -- with one caveat that the APM agent default behaviour is a little surprising. without APMFirst, if we remove APM from // import * as apm from 'elastic-apm-node';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
// apm.start({
// serviceName: 'Nest APM Example',
// serverUrl: 'http://localhost:8200/',
// });
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
setTimeout(() => {
throw new Error('Some error');
}, 3000);
}
bootstrap(); And run this, we get the same crash:
with APMAgain with APM: import * as apm from 'elastic-apm-node';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
apm.start({
serviceName: 'Nest APM Example',
serverUrl: 'http://localhost:8200/',
});
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
setTimeout(() => {
throw new Error('Some error');
}, 3000);
}
bootstrap(); we see almost the same behaviour:
The difference in application behaviour is that the uncaught exception is not printed out before terminating. The For future versions of the APM agent, I think that Did you perhaps expect that APM agent should capture uncaught exceptions and prevent the application from crashing? If so, it might be worth us improving the APM agent docs. |
@trentm Thank you so much for your detailed explanation. Now it really makes sense. When using |
The behavior of the APM agent's default 'uncaughtException' handler can be confusing. Refs: #2359
I've opened #2421 to attempt to somewhat clarify in the docs. This isn't perfect because I'm not sure all users will know to look at the |
The behavior of the APM agent's default 'uncaughtException' handler can be confusing. Refs: #2359
Describe the bug
When using APM with Nest.js, after an uncaught exception, all HTTP requests are refused.
To Reproduce
Steps to reproduce the behavior:
main.ts
with the following code:npm run start:dev
Expected behavior
The application should never return ECONNREFUSED after an uncaught exception.
Environment (please complete the following information)
How are you starting the agent? (please tick one of the boxes)
agent.start()
directly (e.g.require('elastic-apm-node').start(...)
)elastic-apm-node/start
from within the source code-r elastic-apm-node/start
The text was updated successfully, but these errors were encountered: