lib/pitchfork.rb in pitchfork-0.1.2 vs lib/pitchfork.rb in pitchfork-0.2.0

- old
+ new

@@ -55,44 +55,19 @@ else require ru Object.const_get(File.basename(ru, '.rb').capitalize) end - if $DEBUG - require 'pp' - pp({ :inner_app => inner_app }) - end - - return inner_app unless server.default_middleware - - middleware = { # order matters - ContentLength: nil, - Chunked: nil, - CommonLogger: [ $stderr ], - ShowExceptions: nil, - Lint: nil, - TempfileReaper: nil, - } - - # return value, matches rackup defaults based on env - # Pitchfork does not support persistent connections, but Rainbows! - # and Zbatery both do. Users accustomed to the Rack::Server default - # middlewares will need ContentLength/Chunked middlewares. case ENV["RACK_ENV"] when "development" - when "deployment" - middleware.delete(:ShowExceptions) - middleware.delete(:Lint) + Rack::Builder.new do + use(Rack::Lint) + run inner_app + end.to_app else - return inner_app + inner_app end - Rack::Builder.new do - middleware.each do |m, args| - use(Rack.const_get(m), *args) if Rack.const_defined?(m) - end - run inner_app - end.to_app end end # returns an array of strings representing TCP listen socket addresses # and Unix domain socket paths. This is useful for use with @@ -144,15 +119,34 @@ retry else raise end end + + def self.clean_fork(&block) + # We fork from a thread to start with a clean stack. + # If we didn't the base stack would grow after each refork + # putting an effective limit on the number of generations. + parent_thread = Thread.current + Thread.new do + current_thread = Thread.current + # We copy over any thread state it might have + parent_thread.keys.each do |key| + current_thread[key] = parent_thread[key] + end + parent_thread.thread_variables.each do |variable| + current_thread.thread_variable_set(variable, parent_thread.thread_variable_get(variable)) + end + + fork(&block) + end.value + end # :startdoc: end # :enddoc: %w( const socket_helper stream_input tee_input mem_info children message http_parser - refork_condition mold_selector configurator tmpio http_response worker http_server + refork_condition configurator tmpio http_response worker http_server ).each do |s| require_relative "pitchfork/#{s}" end