Skip to content

fix(endpoint-discovery): delete failed cache entry in blocking operations #4011

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

Merged
merged 1 commit into from
Oct 3, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ describe(updateDiscoveredEndpointInCache.name, () => {
);
}
verifyCallsOnCacheUndefined();
expect(mockDelete).not.toHaveBeenCalled();
expect(mockDelete).toHaveBeenCalledTimes(1);
expect(mockDelete).toHaveBeenCalledWith(cacheKey);
expect(mockSet).toHaveBeenCalledTimes(1);
expect(mockSet).toHaveBeenCalledWith(cacheKey, placeholderEndpoints);
});
Expand All @@ -133,7 +134,8 @@ describe(updateDiscoveredEndpointInCache.name, () => {
await updateDiscoveredEndpointInCache(config, options);

verifyCallsOnCacheUndefined();
expect(mockDelete).not.toHaveBeenCalled();
expect(mockDelete).toHaveBeenCalledTimes(1);
expect(mockDelete).toHaveBeenCalledWith(cacheKey);
expect(mockSet).toHaveBeenCalledTimes(2);
expect(mockSet).toHaveBeenNthCalledWith(1, cacheKey, placeholderEndpoints);
expect(mockSet).toHaveBeenNthCalledWith(2, cacheKey, placeholderEndpoints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ export const updateDiscoveredEndpointInCache = async (
resolve();
})
.catch((error: any) => {
if (error.name === "InvalidEndpointException" || error.$metadata?.httpStatusCode === 421) {
// Endpoint is invalid, delete the cache entry.
endpointCache.delete(cacheKey);
}
// The cache entry must be deleted
// because a subsequent blocking request will be stuck
// in a waiting state if it sees the cache entry
// but we have already flushed the request queue.
endpointCache.delete(cacheKey);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This conditional was unnecessary.

  • the cache entry must be deleted in all error cases to unblock the next awaiting request
  • the cache entry placeholder is set below for non-blocking requests anyway


const errorToThrow = Object.assign(
new Error(
Expand Down