[miniflare] A Durable Object that calls a local Artifacts binding cannot be evicted

Aperta
#16,986 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
backend, testing

Direzione di ricerca

Start with packages/miniflare/src/workers/artifacts/wrapped-binding.worker.ts and compare its result handling with the reproduction linked in the issue. Check the Artifacts specs and the reproduction’s eviction test, which calls evictDurableObject(stub) after list(). Done means a disposed list() result no longer prevents eviction; the issue reports that a fix also needs to handle file results and failed get calls.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug package:miniflare product:artifacts
What versions & operating system are you using?
  • miniflare 5.20261117.0-beta
  • workerd 1.20261117.1
  • @cloudflare/vitest-plugin 1.8.3
  • wrangler 4.163.0
  • vitest 5.1.0
  • Node v26.10.0, pnpm 12.7.0, Git 2.43.0
  • Linux x64 for the reproduction. I first saw the same timeout in a larger project on macOS.
Please provide a link to a minimal reproduction

https://github.com/nodnarbnitram/miniflare-artifacts-evict-repro

Describe the Bug

After a Durable Object calls a method of a local Artifacts binding, the object can no longer be evicted, even when it disposes the result of the call. In a test with @cloudflare/vitest-plugin, await evictDurableObject(stub) never settles, and the test times out. The same code is evicted on miniflare 5.20261109.0-beta.

Steps (the reproduction does exactly this):

  1. A Worker has an artifacts binding without remote, and a Durable Object.
  2. A method of the Durable Object runs const result = await this.env.ARTIFACTS.list(); result[Symbol.dispose]?.();.
  3. A test calls that method on a stub, then await evictDurableObject(stub).

What happens, with three tests that each call one method and then evict the object:

miniflare A: no Artifacts call B: list(), result disposed C: list(), result not disposed
5.20261117.0-beta passes times out times out
5.20261109.0-beta (with workerd 1.20261109.1) passes passes times out

What I expect: test B passes on 5.20261117.0-beta, as it does on 5.20261109.0-beta. A caller that disposes its results can be evicted.

Cause, as far as I can tell: since #16771 a local Artifacts binding is a wrapped binding. packages/miniflare/src/workers/artifacts/wrapped-binding.worker.ts reads each RPC result of the namespace service with unwrap(...) and returns only the value, so the caller has nothing to dispose, and the wrapper never disposes the result itself. The one result that it does dispose is a get that succeeds, when the caller disposes the repository handle. A get that fails throws inside unwrap before a disposer is set. The wrapper runs in the caller's isolate (its header comment says so), so the results that are never disposed belong to the Durable Object that made the call.

A fix that works for me: in the wrapper, dispose each result after its value is read (a file result only after its body is read), and dispose a failed get before the error is thrown. With that change, all three tests of the reproduction pass on 5.20261117.0-beta, and the Artifacts specs of Miniflare still pass (130 passed, 1 skipped). I have the change ready with a unit spec and a changeset. I am not a registered collaborator, so I have not opened a pull request; I can open one if you want it. The branch: https://github.com/nodnarbnitram/workers-sdk/tree/fix-artifacts-wrapper-dispose (diff against main).

Please provide any relevant error logs

miniflare 5.20261117.0-beta:

   ✓ A: evicts a Durable Object that did not call Artifacts 9ms
   × B: evicts a Durable Object that called Artifacts and disposed the result 10005ms
   × C: evicts a Durable Object that called Artifacts 10002ms

Error: Test timed out in 10000ms.

 Test Files  1 failed (1)
      Tests  2 failed | 1 passed (3)

miniflare 5.20261109.0-beta with workerd 1.20261109.1:

   ✓ A: evicts a Durable Object that did not call Artifacts 8ms
   ✓ B: evicts a Durable Object that called Artifacts and disposed the result 8ms
   × C: evicts a Durable Object that called Artifacts 10005ms

 Test Files  1 failed (1)
      Tests  1 failed | 2 passed (3)

miniflare 5.20261117.0-beta with the fixed wrapper file in place of the installed one:

 ✓ test/evict.spec.ts (3 tests) 19ms

 Test Files  1 passed (1)
      Tests  3 passed (3)
Lingua principale
TypeScript
Stelle
4.7k
Fork
1.7k
Merge medio
1g 22h
PR unite (30g)
282

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudflare/workers-sdk

Tutte le issue di cloudflare/workers-sdk

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.