search for standard sites pub-search.waow.tech
search zig blog atproto

fix: run schema init in its own thread to unblock local db init

When turso is unreachable, schema.init() hangs indefinitely (no
timeouts in zig 0.15 http.Client). Since it was the first thing in
initServices, it blocked local DB init, sync, and all other services.
Spawn schema init in its own thread so local DB can initialize and
serve search queries even when turso is down.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+8 -2
+8 -2
backend/src/main.zig
··· 73 } 74 75 fn initServices(allocator: std.mem.Allocator) void { 76 - // run schema migrations first (idempotent, but may be slow if turso is laggy) 77 - db.initSchema(); 78 79 // init local db (slow - turso already initialized) 80 db.initLocalDb();
··· 73 } 74 75 fn initServices(allocator: std.mem.Allocator) void { 76 + // run schema migrations in a separate thread — turso may be slow/unreachable 77 + // and we don't want it blocking local db init, sync, or other services 78 + const schema_thread = Thread.spawn(.{}, db.initSchema, .{}) catch |err| { 79 + logfire.warn("failed to spawn schema init thread: {}", .{err}); 80 + // try inline as fallback 81 + db.initSchema(); 82 + }; 83 + schema_thread.detach(); 84 85 // init local db (slow - turso already initialized) 86 db.initLocalDb();