Duplicate search strategy errors to correspond to the number of original requests. This fixes a bug in which more than one search request error would result in a fatal error. (#24952)

This commit is contained in:
CJ Cenizal 2018-11-01 09:48:41 -07:00 committed by GitHub
parent 4c0a5e5a67
commit 0ec2950800
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View file

@ -136,16 +136,25 @@ describe('callClient', () => {
});
it(`still bubbles up the failure`, () => {
const searchRequestFail = createSearchRequest('fail', {
const searchRequestFail1 = createSearchRequest('fail1', {
source: {
getField: () => ({ type: 'fail' }),
},
});
searchRequests = [ searchRequestFail ];
const searchRequestFail2 = createSearchRequest('fail2', {
source: {
getField: () => ({ type: 'fail' }),
},
});
searchRequests = [ searchRequestFail1, searchRequestFail2 ];
return callClient(searchRequests).then(results => {
expect(results).to.eql([{ error: new Error('Search failed') }]);
expect(results).to.eql([
{ error: new Error('Search failed') },
{ error: new Error('Search failed') },
]);
});
});
});

View file

@ -152,6 +152,7 @@ export function CallClientProvider(Private, Promise, es, config) {
abortableSearches.push({
searching,
abort,
requestsCount: searchRequests.length,
});
}
@ -161,7 +162,12 @@ export function CallClientProvider(Private, Promise, es, config) {
return;
}
const segregatedResponses = await Promise.all(abortableSearches.map(({ searching }) => searching.catch((e) => [{ error: e }])));
const segregatedResponses = await Promise.all(abortableSearches.map(async ({ searching, requestsCount }) => {
return searching.catch((e) => {
// Duplicate errors so that they correspond to the original requests.
return new Array(requestsCount).fill({ error: e });
});
}));
// Assigning searchRequests to strategies means that the responses come back in a different
// order than the original searchRequests. So we'll put them back in order so that we can