From c38829848e12d65a2faf2c5aa8d43d4d6de55ca6 Mon Sep 17 00:00:00 2001 From: Harlan GitHub Agent Date: Fri, 9 Oct 2026 01:27:01 +1100 Subject: [PATCH] fix(d1): retry reads blocked by a D1 import job --- server/utils/db.ts | 1 + test/unit/platform-d1.test.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/server/utils/db.ts b/server/utils/db.ts index 227d67f5..cabab6d2 100644 --- a/server/utils/db.ts +++ b/server/utils/db.ts @@ -6,6 +6,7 @@ const D1_TERMINAL_METHODS = new Set(['first', 'run', 'all', 'raw']) const RETRYABLE_D1_READ_MESSAGES = [ 'currently processing a long-running import', 'currently processing a long-running export', + 'currently processing an import job', 'd1 db is overloaded', ] diff --git a/test/unit/platform-d1.test.ts b/test/unit/platform-d1.test.ts index 21b789b2..ca02c9d2 100644 --- a/test/unit/platform-d1.test.ts +++ b/test/unit/platform-d1.test.ts @@ -38,6 +38,20 @@ describe('createPlatformD1', () => { expect(run).toHaveBeenCalledTimes(2) }) + it('retries a read blocked by a D1 import job', async () => { + const run = vi.fn() + .mockRejectedValueOnce(new Error('D1_ERROR: Currently processing an import job.')) + .mockResolvedValue({ id: 1 }) + const { db } = database(run) + const env = { DB: db } as Cloudflare.Env + + const platformDb = createPlatformD1(env, { sleep: async () => {} }).database + const row = await platformDb.prepare('SELECT id FROM skills').first<{ id: number }>() + + expect(row).toEqual({ id: 1 }) + expect(run).toHaveBeenCalledTimes(2) + }) + it('retries a read blocked by a D1 export', async () => { const run = vi.fn() .mockRejectedValueOnce(new Error('D1_ERROR: Currently processing a long-running export.'))