Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
8b33bf2f
Unverified
Commit
8b33bf2f
authored
Aug 13, 2026
by
Hammad Khan
Committed by
GitHub
Aug 13, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(next/image): skip 0-byte entries when initializing disk LRU cache (#94068)
parent
5785f985
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
disk-lru-cache.external.ts
packages/next/src/server/lib/disk-lru-cache.external.ts
+7
-1
lru-disk-eviction.test.ts
test/unit/image-optimizer/lru-disk-eviction.test.ts
+17
-0
No files found.
packages/next/src/server/lib/disk-lru-cache.external.ts
View file @
8b33bf2f
...
@@ -43,7 +43,13 @@ export async function getOrInitDiskLRU(
...
@@ -43,7 +43,13 @@ export async function getOrInitDiskLRU(
const
entries
=
await
readEntries
(
cacheDir
)
const
entries
=
await
readEntries
(
cacheDir
)
for
(
const
entry
of
entries
)
{
for
(
const
entry
of
entries
)
{
lru
.
set
(
entry
.
key
,
entry
.
size
)
// Skip entries with a non-positive size: `LRUCache.set()` rejects
// sizes <= 0, so a single such entry (e.g. a 0-byte or corrupt cache
// file) would otherwise throw here and permanently reject this cached
// singleton promise, breaking the disk cache for the whole process.
if
(
entry
.
size
>
0
)
{
lru
.
set
(
entry
.
key
,
entry
.
size
)
}
}
}
return
lru
return
lru
...
...
test/unit/image-optimizer/lru-disk-eviction.test.ts
View file @
8b33bf2f
...
@@ -164,4 +164,21 @@ describe('LRU disk eviction', () => {
...
@@ -164,4 +164,21 @@ describe('LRU disk eviction', () => {
const
lru
=
await
getOrInitDiskLRU
(
missing
,
1000
,
initEntries
,
rmEntry
)
const
lru
=
await
getOrInitDiskLRU
(
missing
,
1000
,
initEntries
,
rmEntry
)
expect
(
lru
.
size
).
toBe
(
0
)
expect
(
lru
.
size
).
toBe
(
0
)
})
})
it
(
'should skip a 0-byte entry instead of poisoning the singleton'
,
async
()
=>
{
// A 0-byte (empty/corrupt) cache file yields a size-0 entry. `LRUCache.set()`
// rejects sizes <= 0, which previously threw during init and permanently
// rejected the cached singleton promise, breaking the disk cache.
const
expireAt
=
Date
.
now
()
+
60
_000
await
writeEntry
(
cacheDir
,
'valid-a'
,
400
,
expireAt
+
1
)
await
writeEntry
(
cacheDir
,
'empty'
,
0
,
expireAt
+
2
)
await
writeEntry
(
cacheDir
,
'valid-b'
,
400
,
expireAt
+
3
)
// Init must resolve (not reject) and simply skip the 0-byte entry.
const
lru
=
await
getOrInitDiskLRU
(
cacheDir
,
1500
,
initEntries
,
rmEntry
)
expect
(
lru
.
has
(
'empty'
)).
toBe
(
false
)
expect
(
lru
.
has
(
'valid-a'
)).
toBe
(
true
)
expect
(
lru
.
has
(
'valid-b'
)).
toBe
(
true
)
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment