NestJS and Express causing intermittent UnhandledPromiseRejectionWarning











up vote
1
down vote

favorite












I cannot for the life of me cannot figure this out. It happens once every so often doesn't cause any issues with the application itself but i have no idea what is causing this. Im making simultaneous calls to the api from the browser if that has anything to do with it.



[Nest] 16608   - 11/7/2018, 1:23:08 PM   [NestApplication] Nest application successfully started
[Nest] 16608 - 11/7/2018, 1:23:23 PM [LoggerMiddleware] Request /api/observation-statement/pending-count +14943ms
[Nest] 16608 - 11/7/2018, 1:23:23 PM [LoggerMiddleware] Request /api/observation-statement/revision-count +16ms


(node:14968) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:469:11)
at ServerResponse.header (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:767:10)
at ServerResponse.send (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:170:12)
at ServerResponse.json (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:267:15)
at ExpressAdapter.reply (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreadaptersexpress-adapter.js:44:52)
at ExceptionsHandler.catch (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreexceptionsbase-exception-filter.js:16:33)
at ExceptionsHandler.next (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreexceptionsexceptions-handler.js:15:20)
at C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscorerouterrouter-proxy.js:23:35
at Layer.handle_error (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibrouterlayer.js:71:5)
at trim_prefix (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibrouterindex.js:315:13)
(node:14968) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14968) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


I've reduced the calls to a pretty simple function, and make sure the call is returning a unique value (i thought it might be a 304 issue)



@Get('revision-count')
async countRevisions(@User() user, @Param() params) {

user.count ++;

return {
status: 'success',
data: {
rand: user.count,
}
};
}



this was happening prior to the middleware











share|improve this question
























  • Is it possible that somewhere in your application you have an async function that isn't being awaited? The stack trace indicates that your code is falling into the global error handler which returns a default error message but in this case your application has already returned a response to the client so the error handler itself is failing. I had this exact same issue in my app and the underlying was a promise that wasn't being awaited
    – Jesse Carter
    Nov 19 at 19:22










  • i was thinking its the Nest Framework im using or a library.. i have no idea how to track it down though
    – Ricardo Saracino
    Nov 20 at 21:52










  • Are you able to upload a small repo that reproduces this issue?
    – Jesse Carter
    Nov 21 at 14:06















up vote
1
down vote

favorite












I cannot for the life of me cannot figure this out. It happens once every so often doesn't cause any issues with the application itself but i have no idea what is causing this. Im making simultaneous calls to the api from the browser if that has anything to do with it.



[Nest] 16608   - 11/7/2018, 1:23:08 PM   [NestApplication] Nest application successfully started
[Nest] 16608 - 11/7/2018, 1:23:23 PM [LoggerMiddleware] Request /api/observation-statement/pending-count +14943ms
[Nest] 16608 - 11/7/2018, 1:23:23 PM [LoggerMiddleware] Request /api/observation-statement/revision-count +16ms


(node:14968) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:469:11)
at ServerResponse.header (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:767:10)
at ServerResponse.send (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:170:12)
at ServerResponse.json (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:267:15)
at ExpressAdapter.reply (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreadaptersexpress-adapter.js:44:52)
at ExceptionsHandler.catch (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreexceptionsbase-exception-filter.js:16:33)
at ExceptionsHandler.next (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreexceptionsexceptions-handler.js:15:20)
at C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscorerouterrouter-proxy.js:23:35
at Layer.handle_error (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibrouterlayer.js:71:5)
at trim_prefix (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibrouterindex.js:315:13)
(node:14968) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14968) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


I've reduced the calls to a pretty simple function, and make sure the call is returning a unique value (i thought it might be a 304 issue)



@Get('revision-count')
async countRevisions(@User() user, @Param() params) {

user.count ++;

return {
status: 'success',
data: {
rand: user.count,
}
};
}



this was happening prior to the middleware











share|improve this question
























  • Is it possible that somewhere in your application you have an async function that isn't being awaited? The stack trace indicates that your code is falling into the global error handler which returns a default error message but in this case your application has already returned a response to the client so the error handler itself is failing. I had this exact same issue in my app and the underlying was a promise that wasn't being awaited
    – Jesse Carter
    Nov 19 at 19:22










  • i was thinking its the Nest Framework im using or a library.. i have no idea how to track it down though
    – Ricardo Saracino
    Nov 20 at 21:52










  • Are you able to upload a small repo that reproduces this issue?
    – Jesse Carter
    Nov 21 at 14:06













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I cannot for the life of me cannot figure this out. It happens once every so often doesn't cause any issues with the application itself but i have no idea what is causing this. Im making simultaneous calls to the api from the browser if that has anything to do with it.



[Nest] 16608   - 11/7/2018, 1:23:08 PM   [NestApplication] Nest application successfully started
[Nest] 16608 - 11/7/2018, 1:23:23 PM [LoggerMiddleware] Request /api/observation-statement/pending-count +14943ms
[Nest] 16608 - 11/7/2018, 1:23:23 PM [LoggerMiddleware] Request /api/observation-statement/revision-count +16ms


(node:14968) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:469:11)
at ServerResponse.header (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:767:10)
at ServerResponse.send (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:170:12)
at ServerResponse.json (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:267:15)
at ExpressAdapter.reply (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreadaptersexpress-adapter.js:44:52)
at ExceptionsHandler.catch (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreexceptionsbase-exception-filter.js:16:33)
at ExceptionsHandler.next (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreexceptionsexceptions-handler.js:15:20)
at C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscorerouterrouter-proxy.js:23:35
at Layer.handle_error (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibrouterlayer.js:71:5)
at trim_prefix (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibrouterindex.js:315:13)
(node:14968) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14968) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


I've reduced the calls to a pretty simple function, and make sure the call is returning a unique value (i thought it might be a 304 issue)



@Get('revision-count')
async countRevisions(@User() user, @Param() params) {

user.count ++;

return {
status: 'success',
data: {
rand: user.count,
}
};
}



this was happening prior to the middleware











share|improve this question















I cannot for the life of me cannot figure this out. It happens once every so often doesn't cause any issues with the application itself but i have no idea what is causing this. Im making simultaneous calls to the api from the browser if that has anything to do with it.



[Nest] 16608   - 11/7/2018, 1:23:08 PM   [NestApplication] Nest application successfully started
[Nest] 16608 - 11/7/2018, 1:23:23 PM [LoggerMiddleware] Request /api/observation-statement/pending-count +14943ms
[Nest] 16608 - 11/7/2018, 1:23:23 PM [LoggerMiddleware] Request /api/observation-statement/revision-count +16ms


(node:14968) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:469:11)
at ServerResponse.header (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:767:10)
at ServerResponse.send (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:170:12)
at ServerResponse.json (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibresponse.js:267:15)
at ExpressAdapter.reply (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreadaptersexpress-adapter.js:44:52)
at ExceptionsHandler.catch (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreexceptionsbase-exception-filter.js:16:33)
at ExceptionsHandler.next (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscoreexceptionsexceptions-handler.js:15:20)
at C:UsersRicardo SaracinoIdeaProjectssor-apinode_modules@nestjscorerouterrouter-proxy.js:23:35
at Layer.handle_error (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibrouterlayer.js:71:5)
at trim_prefix (C:UsersRicardo SaracinoIdeaProjectssor-apinode_modulesexpresslibrouterindex.js:315:13)
(node:14968) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14968) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


I've reduced the calls to a pretty simple function, and make sure the call is returning a unique value (i thought it might be a 304 issue)



@Get('revision-count')
async countRevisions(@User() user, @Param() params) {

user.count ++;

return {
status: 'success',
data: {
rand: user.count,
}
};
}



this was happening prior to the middleware








javascript node.js typescript express nestjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 21:10









Kim Kern

6,89122241




6,89122241










asked Nov 7 at 18:28









Ricardo Saracino

175112




175112












  • Is it possible that somewhere in your application you have an async function that isn't being awaited? The stack trace indicates that your code is falling into the global error handler which returns a default error message but in this case your application has already returned a response to the client so the error handler itself is failing. I had this exact same issue in my app and the underlying was a promise that wasn't being awaited
    – Jesse Carter
    Nov 19 at 19:22










  • i was thinking its the Nest Framework im using or a library.. i have no idea how to track it down though
    – Ricardo Saracino
    Nov 20 at 21:52










  • Are you able to upload a small repo that reproduces this issue?
    – Jesse Carter
    Nov 21 at 14:06


















  • Is it possible that somewhere in your application you have an async function that isn't being awaited? The stack trace indicates that your code is falling into the global error handler which returns a default error message but in this case your application has already returned a response to the client so the error handler itself is failing. I had this exact same issue in my app and the underlying was a promise that wasn't being awaited
    – Jesse Carter
    Nov 19 at 19:22










  • i was thinking its the Nest Framework im using or a library.. i have no idea how to track it down though
    – Ricardo Saracino
    Nov 20 at 21:52










  • Are you able to upload a small repo that reproduces this issue?
    – Jesse Carter
    Nov 21 at 14:06
















Is it possible that somewhere in your application you have an async function that isn't being awaited? The stack trace indicates that your code is falling into the global error handler which returns a default error message but in this case your application has already returned a response to the client so the error handler itself is failing. I had this exact same issue in my app and the underlying was a promise that wasn't being awaited
– Jesse Carter
Nov 19 at 19:22




Is it possible that somewhere in your application you have an async function that isn't being awaited? The stack trace indicates that your code is falling into the global error handler which returns a default error message but in this case your application has already returned a response to the client so the error handler itself is failing. I had this exact same issue in my app and the underlying was a promise that wasn't being awaited
– Jesse Carter
Nov 19 at 19:22












i was thinking its the Nest Framework im using or a library.. i have no idea how to track it down though
– Ricardo Saracino
Nov 20 at 21:52




i was thinking its the Nest Framework im using or a library.. i have no idea how to track it down though
– Ricardo Saracino
Nov 20 at 21:52












Are you able to upload a small repo that reproduces this issue?
– Jesse Carter
Nov 21 at 14:06




Are you able to upload a small repo that reproduces this issue?
– Jesse Carter
Nov 21 at 14:06

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195616%2fnestjs-and-express-causing-intermittent-unhandledpromiserejectionwarning%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195616%2fnestjs-and-express-causing-intermittent-unhandledpromiserejectionwarning%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()