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

[Security Solution][Exceptions] Handle promise rejections when building artifacts #73831

Merged
merged 3 commits into from
Jul 30, 2020

Conversation

madirey
Copy link
Contributor

@madirey madirey commented Jul 30, 2020

Summary

We weren't properly handling rejected promises when building artifacts, causing Kibana to crash if there's a failure in retrieving the exception list entries.

We first encountered this when building lists that contain 10,000 items, because the pagination was going 1 page past the end of the exception items, resulting in a max window exceeded error from ES. This resulted in an unhandled promise exception that crashed Kibana, necessitating a complete server restart.

The pagination was fixed here: https://github.com/elastic/kibana/pull/73610/files#diff-a4ce84a07372d3782adb00b2f9f1a665R83-R106

... but if we encounter some other error in the findExceptionListItem call chain, we still risk crashing Kibana.

This PR fixes the code so that the promise rejection is handled properly. It was tested manually by forcing a promise rejection in the ExceptionListClient and verifying that 1. an unhandled promise rejection occurred before the fix, and 2. it did NOT occur after the fix.

Before
image

After
image

Checklist

For maintainers

@madirey madirey added v8.0.0 Team:Endpoint Response Endpoint Response Team Feature:Endpoint Elastic Endpoint feature v7.10.0 7.9.0 labels Jul 30, 2020
@madirey madirey requested review from a team as code owners July 30, 2020 16:37
@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-response (Team:Endpoint Response)

@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-app-team (Feature:Endpoint)

mockType: ManifestManagerMockType.ListClientPromiseRejection,
});
await expect(manifestManager.buildNewManifest()).rejects.toThrow();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this test passes without the changes manifest_manager.ts https://github.com/elastic/kibana/pull/73831/files#diff-21a709e8a87929d93a7efdb95905d024R85-R95

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We zoomed. It passes either way, but an UnhandledPromiseRejectionWarning is printed when you run it against the pre-change code, and it's absent now. Doesn't appear to be a way to force jest to behave differently...

Copy link
Contributor

Choose a reason for hiding this comment

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

@madirey explained to me, as posted in the comment, the test will pass without those changes, but the changes prevent the rejection warning from appearing when running the tests. The rejection does get handled further down the line when building the manifest.

@spalger spalger added v7.9.0 and removed 7.9.0 labels Jul 30, 2020
@madirey madirey added the release_note:skip Skip the PR/issue when compiling release notes label Jul 30, 2020
@madirey
Copy link
Contributor Author

madirey commented Jul 30, 2020

@elasticmachine merge upstream

Copy link
Contributor

@dhurley14 dhurley14 left a comment

Choose a reason for hiding this comment

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

LGTM!

packageConfigService?: jest.Mocked<PackageConfigServiceInterface>;
savedObjectsClient?: ReturnType<typeof savedObjectsClientMock.create>;
}): ManifestManager => {
let cache = new LRU<string, Buffer>({ max: 10, maxAge: 1000 * 60 * 60 });
if (opts?.cache !== undefined) {
if (opts?.cache != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ think you want !== instead of !=

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bkimmel Maybe I misunderstood, but I thought the prevailing recommendation was that != null is preferable to !== undefined because it catches both null and undefined...

Copy link
Contributor

Choose a reason for hiding this comment

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

It does, but coercively. == and it's != cousin hurt to read. That fancy new nullish coalescer ?? could come in handy, since it's made to handle undefined/null like if(opts?.cache ?? false) maybe,

Copy link
Contributor

@peluja1012 peluja1012 left a comment

Choose a reason for hiding this comment

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

Thanks for catching this, Madi!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

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

@madirey madirey merged commit c670afa into elastic:master Jul 30, 2020
@madirey madirey deleted the unhandled-promise-rejection branch July 30, 2020 20:00
madirey added a commit to madirey/kibana that referenced this pull request Jul 30, 2020
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
madirey added a commit that referenced this pull request Jul 30, 2020
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
madirey added a commit that referenced this pull request Jul 30, 2020
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jul 31, 2020
* master: (54 commits)
  [ML] Migrate to React BrowserRouter and Kibana provided History. (elastic#71941)
  [Discover] Improve  saveSearch functional test handling (elastic#73626)
  [Metrics UI] Fix all threshold alert conditions disappearing due to alert prefill (elastic#73708)
  [Metrics UI] Fix alert previews of ungrouped alerts (elastic#73735)
  [SIEM] Fixes "include building block button" to operate (elastic#73900)
  [Metrics UI] Fix alert management to open without refresh (elastic#73739)
  [Security Solution][Lists] - Tests cleanup and remove unnecessary import (elastic#73865)
  [Ingest Management] main branch uses epr-snapshot. Others production (elastic#73555)
  [Canvas][tech-debt] Fix SVG not shrinking vertically properly (elastic#73867)
  [Maps] upgrade turf (elastic#73816)
  [Security Solution][Telemetry] Concurrent telemetry requests (elastic#73558)
  [Security Solution][Exceptions] - Update how nested entries are displayed in exceptions viewer (elastic#73745)
  [Security Solution][Exceptions] Adds autocomplete workaround for .text fields (elastic#73761)
  [Metrics UI] Fix previewing of No Data results (elastic#73753)
  Closes elastic#72914 by hiding anomaly detection settings links when the ml plugin is disabled. (elastic#73638)
  [Ingest Manager] Fix config selection in enrollment flyout from config list page (elastic#73833)
  [DOCS] Fixes typo in Alerting actions (elastic#73756)
  [APM] fixes linking errors to ML and Discover (elastic#73758)
  Handle promise rejections when building artifacts (elastic#73831)
  [Security Solution][Detections] Change from sha1 to sha256 (elastic#73741)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jul 31, 2020
* master: (38 commits)
  [Discover] Context unskip date nanos functional tests (elastic#73781)
  [ML] Migrate to React BrowserRouter and Kibana provided History. (elastic#71941)
  [Discover] Improve  saveSearch functional test handling (elastic#73626)
  [Metrics UI] Fix all threshold alert conditions disappearing due to alert prefill (elastic#73708)
  [Metrics UI] Fix alert previews of ungrouped alerts (elastic#73735)
  [SIEM] Fixes "include building block button" to operate (elastic#73900)
  [Metrics UI] Fix alert management to open without refresh (elastic#73739)
  [Security Solution][Lists] - Tests cleanup and remove unnecessary import (elastic#73865)
  [Ingest Management] main branch uses epr-snapshot. Others production (elastic#73555)
  [Canvas][tech-debt] Fix SVG not shrinking vertically properly (elastic#73867)
  [Maps] upgrade turf (elastic#73816)
  [Security Solution][Telemetry] Concurrent telemetry requests (elastic#73558)
  [Security Solution][Exceptions] - Update how nested entries are displayed in exceptions viewer (elastic#73745)
  [Security Solution][Exceptions] Adds autocomplete workaround for .text fields (elastic#73761)
  [Metrics UI] Fix previewing of No Data results (elastic#73753)
  Closes elastic#72914 by hiding anomaly detection settings links when the ml plugin is disabled. (elastic#73638)
  [Ingest Manager] Fix config selection in enrollment flyout from config list page (elastic#73833)
  [DOCS] Fixes typo in Alerting actions (elastic#73756)
  [APM] fixes linking errors to ML and Discover (elastic#73758)
  Handle promise rejections when building artifacts (elastic#73831)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Endpoint Elastic Endpoint feature release_note:skip Skip the PR/issue when compiling release notes Team:Endpoint Response Endpoint Response Team v7.9.0 v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants