-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Search] fix cancelation related memory leaks #81996
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,13 @@ import { PublicMethodsOf } from '@kbn/utility-types'; | |
import { CoreStart, CoreSetup, ToastsSetup } from 'kibana/public'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
getCombinedSignal, | ||
AbortError, | ||
IKibanaSearchRequest, | ||
IKibanaSearchResponse, | ||
ISearchOptions, | ||
ES_SEARCH_STRATEGY, | ||
ISessionService, | ||
getCombinedController, | ||
} from '../../common'; | ||
import { SearchUsageCollector } from './collectors'; | ||
import { | ||
|
@@ -171,16 +171,17 @@ export class SearchInterceptor { | |
...(abortSignal ? [abortSignal] : []), | ||
]; | ||
|
||
const combinedSignal = getCombinedSignal(signals); | ||
const combinedController = getCombinedController(signals); | ||
const cleanup = () => { | ||
subscription.unsubscribe(); | ||
combinedController.signal.removeEventListener('abort', cleanup); | ||
combinedController.abort(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the reason we need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, exactly.
Agree. Done! |
||
}; | ||
|
||
combinedSignal.addEventListener('abort', cleanup); | ||
combinedController.signal.addEventListener('abort', cleanup); | ||
|
||
return { | ||
timeoutSignal, | ||
combinedSignal, | ||
combinedSignal: combinedController.signal, | ||
cleanup, | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ describe('ExecutionContract', () => { | |
|
||
test('can cancel execution', () => { | ||
const execution = createExecution('foo bar=123'); | ||
const spy = jest.spyOn(execution, 'cancel'); | ||
const spy = jest.spyOn(execution, 'cancel').mockImplementation(() => {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that test were silently failing tests (on master)
I assume that it warns is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just fixed that particular higher level test, but really, probably we should also handle and test edge case:
|
||
const contract = new ExecutionContract(execution); | ||
|
||
expect(spy).toHaveBeenCalledTimes(0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not a huge fan of adding a method to a built-in class (
Promise
). We might consider returning an object instead (like{ promise, cleanup }
). I think it will also help to enforce that any consumers of this function will handle cleaning up and not just use the promise returned.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind initial approach I took mostly because it is clearly typed that it has a
cleanup
method, nevertheless:I agree with this 👍 changed
{promise, cleanup}
one tiny caveat is that now we can't just use:
but have to: