Skip to content

SqliteCacheStore createWriteStream() enforces maxEntrySize incorrectly for streamed cache writes #5128

@trivikr

Description

@trivikr

Bug Description

SqliteCacheStore#createWriteStream() enforces maxEntrySize incorrectly for streamed cache writes.

Reproducible By

import { strictEqual } from 'node:assert'
import { once } from 'node:events'
import { cacheStores } from 'undici'

const body = Buffer.from('abc')
const maxEntrySize = body.byteLength
const now = Date.now()

const value = {
  statusCode: 200,
  statusMessage: 'OK',
  headers: {},
  cachedAt: now,
  staleAt: now + 60_000,
  deleteAt: now + 120_000
}

const key = (path) => ({
  origin: 'https://example.com',
  method: 'GET',
  path,
  headers: {}
})

const store = new cacheStores.SqliteCacheStore({ maxEntrySize })

const stream = store.createWriteStream(key('/stream'), value)
stream.end(body)
await once(stream, 'close')

strictEqual(store.get(key('/stream')).body.toString(), 'abc')

store.close()

Expected Behavior

Assertion to be successful, as body is of maxEntrySize

const body = Buffer.from('abc')
const maxEntrySize = body.byteLength

Logs & Screenshots

An error is thrown since the entry is undefined

strictEqual(store.get(key('/stream')).body.toString(), 'abc')
                                     ^

TypeError: Cannot read properties of undefined (reading 'body')
    at file:///Users/trivikram/workspace/test-repro/test.mjs:31:38
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)

Node.js v24.15.0

Environment

macOS 26.4.1
Node v24.15.0
undici v8.1.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions