From 4af4a006d1f1a214ee0b2c97c5ee401f76064911 Mon Sep 17 00:00:00 2001 From: Alex Lance Date: Sun, 4 Jun 2017 23:18:54 +1000 Subject: [PATCH] Config first data timeout (#1111) * Permit the first_data_timeout setting to be overridden in the DSL * Add option --- lib/puma/configuration.rb | 3 ++- lib/puma/dsl.rb | 6 ++++++ lib/puma/server.rb | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 98243e71be..47f9401e44 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -183,7 +183,8 @@ def puma_default_options :environment => ->{ ENV['RACK_ENV'] || "development" }, :rackup => DefaultRackup, :logger => STDOUT, - :persistent_timeout => Const::PERSISTENT_TIMEOUT + :persistent_timeout => Const::PERSISTENT_TIMEOUT, + :first_data_timeout => Const::FIRST_DATA_TIMEOUT } end diff --git a/lib/puma/dsl.rb b/lib/puma/dsl.rb index 51b1722c9c..eca8fe71f8 100644 --- a/lib/puma/dsl.rb +++ b/lib/puma/dsl.rb @@ -132,6 +132,12 @@ def persistent_timeout(seconds) @options[:persistent_timeout] = seconds end + # Define how long the tcp socket stays open, if no data has been received + # + def first_data_timeout(seconds) + @options[:first_data_timeout] = seconds + end + # Work around leaky apps that leave garbage in Thread locals # across requests # diff --git a/lib/puma/server.rb b/lib/puma/server.rb index 97efa85735..8516463988 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -64,12 +64,11 @@ def initialize(app, events=Events.stdio, options={}) @thread_pool = nil @persistent_timeout = options.fetch(:persistent_timeout, PERSISTENT_TIMEOUT) + @first_data_timeout = options.fetch(:first_data_timeout, FIRST_DATA_TIMEOUT) @binder = Binder.new(events) @own_binder = true - @first_data_timeout = FIRST_DATA_TIMEOUT - @leak_stack_on_error = true @options = options