Skip to content
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

Give better stack traces for Unhandled Promise Rejection warnings #60235

Merged
merged 1 commit into from
Mar 17, 2020

Conversation

watson
Copy link
Contributor

@watson watson commented Mar 16, 2020

This specialized warning listener will only be in effect during development and CI. Under normal production operation where the --no-warnings flag is used, we'll not attach the unhandledRejection listener.

@watson watson added Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.0.0 v7.7.0 Feature:Hardening Harding of Kibana from a security perspective labels Mar 16, 2020
@watson watson requested a review from a team as a code owner March 16, 2020 09:25
@watson watson self-assigned this Mar 16, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@watson watson added the release_note:skip Skip the PR/issue when compiling release notes label Mar 16, 2020
@watson watson requested a review from pgayvallet March 16, 2020 09:26
Comment on lines +42 to +49
process.on('unhandledRejection', function(reason) {
console.error('Unhandled Promise rejection detected:');
console.error();
console.error(reason);
console.error();
console.error('Terminating process...');
process.exit(1);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already catched by the warning event?

From https://kibana-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/elastic+kibana+pipeline-pull-request/runs/33334/nodes/28/steps/147/log/?start=0

Node.js process-warning detected:
[2020-03-16T08:30:26.360Z] 
[2020-03-16T08:30:26.360Z] UnhandledPromiseRejectionWarning: [object Object]
[2020-03-16T08:30:26.360Z]     at emitWarning (internal/process/promises.js:99:15)
[2020-03-16T08:30:26.360Z]     at emitPromiseRejectionWarnings (internal/process/promises.js:143:7)
[2020-03-16T08:30:26.360Z]     at process._tickCallback (internal/process/next_tick.js:69:34)
[2020-03-16T08:30:26.360Z] 
[2020-03-16T08:30:26.360Z] Terminating process...
[2020-03-16T08:30:26.360Z] Fatal error: jest exited with code 1�

Or will the reason catched by the unhandledRejection contains more info than what is catched by the warning handler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stack trace available for the unhandled exception is just pointing back to a next-tick frame which doesn't show any of the user-land code. This makes the stack trace unusable and the reader can't see which Promise was not handled correctly.

By implementing an unhandledRejection listener we get access to the rejection reason, which hopefully always is an Error object with its own stack trace. We can use this stack trace to guide the developer towards the location where the Promise rejection wasn't handled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the question :) great then.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@watson watson merged commit 56010b1 into elastic:master Mar 17, 2020
@watson watson deleted the promise-rejection-error branch March 17, 2020 07:33
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 17, 2020
* master: (30 commits)
  [TSVB] fix text color when using custom background color (elastic#60261)
  Fix import to timefilter from in TSVB (elastic#60296)
  [NP] Get rid of usage redirectWhenMissing service (elastic#59777)
  [SIEM] Fix Timeline footer styling (elastic#59587)
  [ML] Fixes to error handling for analytics jobs and file data viz (elastic#60249)
  Give better stack traces for Unhandled Promise Rejection warnings (elastic#60235)
  resolves elastic#58905 (elastic#60120)
  Added variables button for text fields in Pagerduty component. (elastic#60189)
  adds test that action vars are rendered for alert action parms (elastic#60310)
  Closes 59786 by removing the update toast (elastic#60172)
  [EPM] Packages list tabs (elastic#60167)
  Added message variables button for Webhook body form field (elastic#60174)
  Revert "adds new test (elastic#60064)"
  [Maps] move MapSavedObject type out of telemetry (elastic#60127)
  [Reporting] Fix error handling for job handler in route (elastic#60161)
  [Endpoint] TEST: verify alerts page header says 'Alerts' (elastic#60206)
  EMT-248: implement ack resource to accept event payload to acknowledge agent actions (elastic#60218)
  Migrate dual validated range (elastic#59689)
  Embeddable triggers (elastic#58440)
  [Endpoint] Sample data generator CLI script (elastic#59952)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Hardening Harding of Kibana from a security perspective release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants