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

Fix regression in CallClient, which caused request errors like timeouts to result in fatal errors #22558

Merged
merged 1 commit into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/ui/public/courier/fetch/__tests__/call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,35 @@ describe('callClient', () => {
expect(results).to.eql([1]);
});
});

it(`resolves the promise despite the request failing`, () => {
addSearchStrategy({
id: 'fail',
isViable: indexPattern => {
return indexPattern.type === 'fail';
},
search: () => {
return {
searching: Promise.reject(new Error('Search failed')),
failedSearchRequests: [],
abort: () => {},
};
},
});

const searchRequestFail = createSearchRequest('fail', {
source: {
getField: () => ({ type: 'fail' }),
},
});

searchRequests = [ searchRequestFail ];
const callingClient = callClient(searchRequests);

return callingClient.then(results => {
expect(results).to.eql(undefined);
});
});
});

describe('implementation', () => {
Expand Down
11 changes: 6 additions & 5 deletions src/ui/public/courier/fetch/call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,18 @@ export function CallClientProvider(Private, Promise, es) {
}
});

// If there are any errors, notify the searchRequests of them.
defer.promise.catch((err) => {
Copy link
Contributor Author

@cjcenizal cjcenizal Aug 30, 2018

Choose a reason for hiding this comment

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

By returning the original defer.promise instead of the result of calling defer.promise.catch(), we created two parallel promise chains which would both catch the same error. By returning the result of defer.promise.catch(), we preserve the single promise chain, allowing us to prevent errors from reaching the consumer (fetch_now.js). The consumer creates fatal errors in response to rejected promises.

// Return the promise which acts as our vehicle for providing search responses to the consumer.
// However, if there are any errors, notify the searchRequests of them *instead* of bubbling
// them up to the consumer.
return defer.promise.catch((err) => {
// By returning the return value of this catch() without rethrowing the error, we delegate
// error-handling to the searchRequest instead of the consumer.
searchRequests.forEach((searchRequest, index) => {
if (searchRequestsAndStatuses[index] !== ABORTED) {
searchRequest.handleFailure(err);
}
});
});

// Return the promise which acts as our vehicle for providing search responses to the consumer.
return defer.promise;
}

return callClient;
Expand Down