Skip to content

Commit 5727459

Browse files
committed
Attempt to restart OOM bun process
1 parent f3797e8 commit 5727459

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/celestite.cr

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@ module Celestite
2020
def self.render(component : String?, context : Celestite::Context? = nil, layout : String? = nil)
2121
if renderer = @@renderer
2222
if proc = renderer.node_process
23-
raise ProcessException.new("Error rendering - node process is dead", renderer.errors) if proc.terminated?
23+
if proc.terminated?
24+
Log.for("celestite").warn { "Node process died - attempting restart..." }
25+
# Remove old process from tracking
26+
@@node_processes.delete(proc)
27+
# Start a new process
28+
new_proc = renderer.start_server
29+
@@node_processes << new_proc
30+
# Wait briefly for the new process to be ready
31+
sleep 2.seconds
32+
# Check if new process is healthy
33+
if new_proc.terminated?
34+
raise ProcessException.new("Error rendering - node process failed to restart", renderer.errors)
35+
end
36+
Log.for("celestite").info { "Node process restarted successfully" }
37+
end
2438
renderer.render(component, context, layout)
2539
end
2640
end

src/celestite/renderer.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Celestite
1111
getter config : Config
1212
getter node_process : Process?
1313
getter errors = IO::Memory.new
14+
@process_command : String = ""
1415

1516
Log = ::Log.for("celestite".colorize(:light_green).to_s)
1617

0 commit comments

Comments
 (0)