Skip to content

[Search] Memory leaks caused by AbortController #65051

@Dosant

Description

@Dosant

While digging into search code noticed potential improvements around requests cancelation:

  1. When firing search requests we subscribe to abort signal
abort.signal.addEventListener('abort', () => {
cancel()
}) 

But it could happen that client already asked to abort request and it seems to handle that case we have to handle it separately:

e.g.:

const { abortSignal = null } = requestOptionsMap.get(request) || {};
if (abortSignal) {
  if (abortSignal.aborted) {
    abort();
  } else {
    abortSignal.addEventListener('abort', abort);
  }
}

Such scenario happened to me in dashboard.

  1. I guess that every time we manually subscribe to abort event, we have to unsubscribe also? otherwise it is a memory leak. abortSignal.addEventListener('abort', abort);. note: RxJS fromEvent handle unsubscribe when we unsubscribe from observable.

To confirm this is needed, for example, fetch polyfill does this: https://github.com/github/fetch/blob/master/fetch.js#L534

Metadata

Metadata

Assignees

Labels

Feature:SearchQuerying infrastructure in KibanabugFixes for quality problems that affect the customer experienceimpact:highAddressing this issue will have a high level of impact on the quality/strength of our product.loe:mediumMedium Level of Effortv7.9.0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions