diff --git a/packages/typescript-client/src/client.ts b/packages/typescript-client/src/client.ts index bc64a06054..344540b70a 100644 --- a/packages/typescript-client/src/client.ts +++ b/packages/typescript-client/src/client.ts @@ -623,6 +623,7 @@ export class ShapeStream = Row> #fastLoopMaxCount = 5 #pendingRequestShapeCacheBuster?: string #maxSnapshotRetries = 5 + _expiredShapeRecoveryKey: string | null = null constructor(options: ShapeStreamOptions>) { this.options = { subscribe: true, ...options } @@ -1241,6 +1242,14 @@ export class ShapeStream = Row> // Cancel the response body to release the connection before retrying. await response.body?.cancel() if (transition.exceededMaxRetries) { + if (shapeKey && this._expiredShapeRecoveryKey !== shapeKey) { + this._expiredShapeRecoveryKey = shapeKey + expiredShapesCache.delete(shapeKey) + this.#reset() + throw new StaleCacheError( + `Expired handle entry evicted for self-healing retry` + ) + } throw new FetchError( 502, undefined,