Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add health_check_timeout for detecting hung servers. #270

Merged
merged 2 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion falcon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 3.1"

spec.add_dependency "async"
spec.add_dependency "async-container", "~> 0.18"
spec.add_dependency "async-container", "~> 0.20"
spec.add_dependency "async-http", "~> 0.75"
spec.add_dependency "async-http-cache", "~> 0.4"
spec.add_dependency "async-service", "~> 0.10"
Expand Down
4 changes: 3 additions & 1 deletion lib/falcon/command/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ class Serve < Samovar::Command

option "--[no]-restart", "Enable/disable automatic restart.", default: true
option "--graceful-stop <timeout>", "Duration to wait for graceful stop.", type: Float, default: 1.0

option "--health-check-timeout <duration>", "Duration to wait for health check.", type: Float, default: 30.0
end

def container_options
@options.slice(:count, :forks, :threads, :restart)
@options.slice(:count, :forks, :threads, :restart, :health_check_timeout)
end

def endpoint_options
Expand Down
2 changes: 1 addition & 1 deletion lib/falcon/environment/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def count

# Options to use when creating the container.
def container_options
{restart: true, count: self.count}.compact
{restart: true, count: self.count, health_check_timeout: 30}.compact
end

# The host that this server will receive connections for.
Expand Down
11 changes: 11 additions & 0 deletions lib/falcon/service/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def start
# @parameter container [Async::Container::Generic]
def setup(container)
container_options = @evaluator.container_options
health_check_timeout = container_options[:health_check_timeout]

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

instance.ready!

if health_check_timeout
Async(transient: true) do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while true
instance.name = "#{server} load=#{Fiber.scheduler.load}"
sleep(health_check_timeout / 2)
instance.ready!
end
end
end

task.children.each(&:wait)
end
end
Expand Down
Loading