diff --git a/src/main.zig b/src/main.zig index 3577ac1..1ee54d3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -5,6 +5,12 @@ const auth = @import("auth.zig"); const version = @import("build_options").git_revision; +fn exitAfterDelay() void { + std.Thread.sleep(500 * std.time.ns_per_ms); + std.log.err("Notmuch search is in unrecoverable state: exiting", .{}); + std.process.exit(1); +} + pub fn main() !u8 { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); @@ -208,6 +214,13 @@ fn queryHandler(db: *root.NotmuchDb, req: *httpz.Request, res: *httpz.Response) const query = std.Uri.percentDecodeInPlace(query_buf); var threads = db.search(query) catch |err| { + if (err == error.CouldNotSearchThreads) { + res.status = 503; + try res.json(.{ .@"error" = "CouldNotSearchThreads", .fatal = true }, .{}); + const exit_thread = std.Thread.spawn(.{}, exitAfterDelay, .{}) catch @panic("could not spawn thread to kill process"); + exit_thread.detach(); + return; + } res.status = 500; try res.json(.{ .@"error" = @errorName(err) }, .{}); return; diff --git a/static/index.html b/static/index.html index 5516934..6c8cfee 100644 --- a/static/index.html +++ b/static/index.html @@ -48,6 +48,11 @@ button:disabled { background: #444; cursor: not-allowed; } .login-box h2 { margin-bottom: 1rem; } .login-box input { width: 100%; padding: 0.5rem; margin-bottom: 1rem; border: 1px solid #444; border-radius: 4px; background: #2a2a2a; color: #e0e0e0; } .login-box button { width: 100%; } +.restart-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.9); z-index: 3000; align-items: center; justify-content: center; } +.restart-overlay.visible { display: flex; } +.restart-box { background: #252525; border: 1px solid #444; border-radius: 8px; padding: 2rem; text-align: center; } +.restart-box h2 { margin-bottom: 1rem; color: #ff6b6b; } +.restart-box p { margin-bottom: 1rem; color: #999; } @@ -107,6 +112,14 @@ button:disabled { background: #444; cursor: not-allowed; } + +
+
+

Server Restarting

+

The server encountered a fatal error and is restarting...

+

Retrying in 5 seconds

+
+