Skip to content

Commit 1361670

Browse files
committed
fix: fragment-do init race — same pattern as query-do (promise serialization)
1 parent 1fcfe79 commit 1361670

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/fragment-do.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class FragmentDO extends DurableObject<Env> {
3434
private wasmEngine!: WasmEngine;
3535
/** Footer cache keyed by r2Key — survives across scans while the DO is alive. */
3636
private footerCache = new Map<string, TableMeta>();
37-
private initialized = false;
37+
private initPromise: Promise<void> | null = null;
3838

3939
constructor(ctx: DurableObjectState, env: Env) {
4040
super(ctx, env);
@@ -46,10 +46,14 @@ export class FragmentDO extends DurableObject<Env> {
4646
);
4747
}
4848

49-
private async ensureInitialized(): Promise<void> {
50-
if (this.initialized) return;
51-
this.initialized = true;
49+
private ensureInitialized(): Promise<void> {
50+
if (!this.initPromise) {
51+
this.initPromise = this.doInit();
52+
}
53+
return this.initPromise;
54+
}
5255

56+
private async doInit(): Promise<void> {
5357
// Restore footer cache from SQLite (survives hibernation)
5458
const stored = await this.ctx.storage.list<TableMeta>({ prefix: "frag:" });
5559
for (const [key, meta] of stored) this.footerCache.set(key.replace("frag:", ""), meta);

0 commit comments

Comments
 (0)