-
Notifications
You must be signed in to change notification settings - Fork 171
Fix locked readable stream in composable cache #939
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
Conversation
🦋 Changeset detectedLatest commit: 6a34a21 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
Coverage Report
File Coverage
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Fixes a locked readable stream issue in the composable cache by improving how pending cache entries are handled. The solution prevents stream locking by ensuring that ReadableStreams are properly converted to strings before storing and recreated when retrieving from the pending write map.
- Updates pending write promise mapping to handle string values instead of streams
- Improves stream handling during cache get operations for pending entries
- Adds comprehensive test coverage for the composable cache functionality
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
packages/open-next/src/adapters/composable-cache.ts | Fixes stream locking by converting streams to strings in pending writes and recreating streams on retrieval |
packages/tests-unit/tests/adapters/composable-cache.test.ts | Adds comprehensive test suite covering all cache operations including concurrent access scenarios |
.changeset/wet-emus-brake.md | Documents the fix for locked readable stream issue |
Comments suppressed due to low confidence (2)
packages/open-next/src/adapters/composable-cache.ts:7
- [nitpick] The variable name
pendingWritePromiseMap
could be more concise. Consider renaming topendingWrites
orpendingEntries
for better readability.
const pendingWritePromiseMap = new Map<
packages/tests-unit/tests/adapters/composable-cache.test.ts:404
- The variable name
writtenTags
shadows the global variable declared at line 50. Consider renaming towrittenTagsCall
oractualWrittenTags
to avoid confusion.
const writtenTags = tagCache.writeTags.mock.calls[0][0];
invalidatePaths: vi.fn(), | ||
}; | ||
globalThis.cdnInvalidationHandler = invalidateCdnHandler; | ||
let writtenTags = new Set(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The writtenTags
variable is declared with let
but could be const
since it's reassigned in beforeEach
blocks rather than mutated directly.
let writtenTags = new Set(); | |
const writtenTags = new Set(); |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This AI just stole my job!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It stole mine as well. It wrote a lot of the unit test 😄
// If we do, we return the pending promise instead of fetching the cache | ||
if (pendingWritePromiseMap.has(cacheKey)) { | ||
return pendingWritePromiseMap.get(cacheKey); | ||
const stored = pendingWritePromiseMap.get(cacheKey)!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a scenario where set
doesn't get called and this returns undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of any, but I can add a check just in case. And it will stop typescript complaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for the review! |
Update handling of pending writes to prevent locked readable streams in the composable cache. This change improves the management of cache entries and ensures proper stream handling.
I want to make some test first, as this one will increase memory usage, which could be an issue in cloudflareSeems to be working fine