Skip to content

Commit 743aad4

Browse files
committed
Add health_check_timeout for detecting hung servers.
1 parent 2cba71e commit 743aad4

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

falcon.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
2727
spec.required_ruby_version = ">= 3.1"
2828

2929
spec.add_dependency "async"
30-
spec.add_dependency "async-container", "~> 0.18"
30+
spec.add_dependency "async-container", "~> 0.20"
3131
spec.add_dependency "async-http", "~> 0.75"
3232
spec.add_dependency "async-http-cache", "~> 0.4"
3333
spec.add_dependency "async-service", "~> 0.10"

lib/falcon/command/serve.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ class Serve < Samovar::Command
4545

4646
option "--[no]-restart", "Enable/disable automatic restart.", default: true
4747
option "--graceful-stop <timeout>", "Duration to wait for graceful stop.", type: Float, default: 1.0
48+
49+
option "--health-check-timeout <duration>", "Duration to wait for health check.", type: Float, default: 30.0
4850
end
4951

5052
def container_options
51-
@options.slice(:count, :forks, :threads, :restart)
53+
@options.slice(:count, :forks, :threads, :restart, :health_check_timeout)
5254
end
5355

5456
def endpoint_options

lib/falcon/environment/server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def count
3333

3434
# Options to use when creating the container.
3535
def container_options
36-
{restart: true, count: self.count}.compact
36+
{restart: true, count: self.count, health_check_timeout: 30}.compact
3737
end
3838

3939
# The host that this server will receive connections for.

lib/falcon/service/server.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def start
5252
# @parameter container [Async::Container::Generic]
5353
def setup(container)
5454
container_options = @evaluator.container_options
55+
health_check_timeout = container_options[:health_check_timeout]
5556

5657
container.run(name: self.name, **container_options) do |instance|
5758
evaluator = @environment.evaluator
@@ -63,6 +64,16 @@ def setup(container)
6364

6465
instance.ready!
6566

67+
if health_check_timeout
68+
Async(transient: true) do
69+
while true
70+
instance.name = "#{server} load=#{Fiber.scheduler.load}"
71+
sleep(health_check_timeout / 2)
72+
instance.ready!
73+
end
74+
end
75+
end
76+
6677
task.children.each(&:wait)
6778
end
6879
end

0 commit comments

Comments
 (0)