Skip to content

Commit c96ac94

Browse files
authored
fix(endpoint-discovery): delete failed cache entry in blocking operations (#4011)
1 parent 8fe1b54 commit c96ac94

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/middleware-endpoint-discovery/src/updateDiscoveredEndpointInCache.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ describe(updateDiscoveredEndpointInCache.name, () => {
120120
);
121121
}
122122
verifyCallsOnCacheUndefined();
123-
expect(mockDelete).not.toHaveBeenCalled();
123+
expect(mockDelete).toHaveBeenCalledTimes(1);
124+
expect(mockDelete).toHaveBeenCalledWith(cacheKey);
124125
expect(mockSet).toHaveBeenCalledTimes(1);
125126
expect(mockSet).toHaveBeenCalledWith(cacheKey, placeholderEndpoints);
126127
});
@@ -133,7 +134,8 @@ describe(updateDiscoveredEndpointInCache.name, () => {
133134
await updateDiscoveredEndpointInCache(config, options);
134135

135136
verifyCallsOnCacheUndefined();
136-
expect(mockDelete).not.toHaveBeenCalled();
137+
expect(mockDelete).toHaveBeenCalledTimes(1);
138+
expect(mockDelete).toHaveBeenCalledWith(cacheKey);
137139
expect(mockSet).toHaveBeenCalledTimes(2);
138140
expect(mockSet).toHaveBeenNthCalledWith(1, cacheKey, placeholderEndpoints);
139141
expect(mockSet).toHaveBeenNthCalledWith(2, cacheKey, placeholderEndpoints);

packages/middleware-endpoint-discovery/src/updateDiscoveredEndpointInCache.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ export const updateDiscoveredEndpointInCache = async (
5454
resolve();
5555
})
5656
.catch((error: any) => {
57-
if (error.name === "InvalidEndpointException" || error.$metadata?.httpStatusCode === 421) {
58-
// Endpoint is invalid, delete the cache entry.
59-
endpointCache.delete(cacheKey);
60-
}
57+
// The cache entry must be deleted
58+
// because a subsequent blocking request will be stuck
59+
// in a waiting state if it sees the cache entry
60+
// but we have already flushed the request queue.
61+
endpointCache.delete(cacheKey);
6162

6263
const errorToThrow = Object.assign(
6364
new Error(

0 commit comments

Comments
 (0)