Skip to content

Commit

Permalink
fix(endpoint-discovery): delete failed cache entry in blocking operat…
Browse files Browse the repository at this point in the history
…ions (#4011)
  • Loading branch information
kuhe authored Oct 3, 2022
1 parent 8fe1b54 commit c96ac94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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);

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

0 comments on commit c96ac94

Please sign in to comment.