1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Adds thread request blockage logging when USR1 is toggled.

git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@334 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
zedshaw 2006-08-22 06:01:35 +00:00
parent af538004f5
commit 4503684825
2 changed files with 26 additions and 5 deletions

View file

@ -577,7 +577,10 @@ module Mongrel
break #done
else
# Parser is not done, queue up more data to read and continue parsing
data << client.readpartial(Const::CHUNK_SIZE)
chunk = client.readpartial(Const::CHUNK_SIZE)
break if !chunk or chunk.length == 0 # read failed, stop processing
data << chunk
if data.length >= Const::MAX_HEADER
raise HttpParserError.new("HEADER is longer than allowed, aborting client early.")
end
@ -586,8 +589,8 @@ module Mongrel
rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF
# ignored
rescue HttpParserError
STDERR.puts "#{Time.now}: BAD CLIENT (#{params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last}): #$!"
if $mongrel_debug_client
STDERR.puts "#{Time.now}: BAD CLIENT (#{params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last}): #$!"
STDERR.puts "#{Time.now}: REQUEST DATA: #{data.inspect}\n---\nPARAMS: #{params.inspect}\n---\n"
end
rescue Errno::EMFILE
@ -680,6 +683,9 @@ module Mongrel
rescue Errno::ECONNABORTED
# client closed the socket even before accept
client.close rescue Object
rescue Object => exc
STDERR.puts "!!!!!! UNHANDLED EXCEPTION! #{exc}. TELL ZED HE'S A MORON."
STDERR.puts $!.backtrace.join("\n") if $mongrel_debug_client
end
end

View file

@ -7,6 +7,11 @@
require 'mongrel'
require 'cgi'
class Mutex
# modified to open the waiting list for reporting purposes
attr_accessor :waiting
end
module Mongrel
module Rails
# Implements a handler that can run Rails and serve files out of the
@ -37,6 +42,7 @@ module Mongrel
def initialize(dir, mime_map = {})
@files = Mongrel::DirHandler.new(dir,false)
@guard = Mutex.new
@tick = Time.now
# register the requested mime types
mime_map.each {|k,v| Mongrel::DirHandler::add_mime_type(k,v) }
@ -69,7 +75,7 @@ module Mongrel
# we don't want the output to be really final until we're out of the lock
cgi.default_really_final = false
lock!
lock! request.params[Mongrel::Const::PATH_INFO]
Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
@ -88,20 +94,29 @@ module Mongrel
end
end
def lock!
def lock!(path)
# ultra dangerous, but people are asking to kill themselves. here's the Katana
log_threads_waiting_for path
@guard.lock unless ActionController::Base.allow_concurrency
end
def unlock!
log_threads_waiting_for "unlock"
@guard.unlock unless ActionController::Base.allow_concurrency
end
def log_threads_waiting_for(event)
if $mongrel_debug_client and (Time.now - @tick > 10)
STDERR.puts "#{Time.now}: #{@guard.waiting.length} threads waiting for #{event}."
@tick = Time.now
end
end
# Does the internal reload for Rails. It might work for most cases, but
# sometimes you get exceptions. In that case just do a real restart.
def reload!
begin
lock!
lock! "RAILS RELOAD"
$".replace $orig_dollar_quote
GC.start
Dispatcher.reset_application!