From 5868eeecb2fbc85f3e4fabf3d16f27d259491c0d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 26 Nov 2009 14:09:45 -0800 Subject: cleanup and refactor error handling Make sure app errors get logged correctly, and we no longer return a 500 response when a client EOFs the write end (but not the read end) of a connection. --- lib/rainbows/revactor.rb | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'lib/rainbows/revactor.rb') diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb index 489236c..4e4b381 100644 --- a/lib/rainbows/revactor.rb +++ b/lib/rainbows/revactor.rb @@ -63,11 +63,11 @@ module Rainbows out = [ alive ? CONN_ALIVE : CONN_CLOSE ] if hp.headers? HttpResponse.write(client, response, out) end while alive and hp.reset.nil? and env.clear - client.close rescue ::Revactor::TCP::ReadError - client.close rescue => e handle_error(client, e) + ensure + client.close end # runs inside each forked worker, this sits around and waits @@ -95,8 +95,8 @@ module Rainbows clients[actor.object_id] = actor root.link(actor) rescue Errno::EAGAIN, Errno::ECONNABORTED - rescue Object => e - listen_loop_error(e) + rescue => e + Error.listen_loop(e) end while G.alive end end @@ -119,23 +119,10 @@ module Rainbows # if the socket is already closed or broken. We'll always ensure # the socket is closed at the end of this function def handle_error(client, e) - msg = case e - when EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF - Const::ERROR_500_RESPONSE - when HttpParserError # try to tell the client they're bad - Const::ERROR_400_RESPONSE - else - logger.error "Read error: #{e.inspect}" - logger.error e.backtrace.join("\n") - Const::ERROR_500_RESPONSE - end - client.instance_eval do - # this is Revactor implementation dependent - @_io.write_nonblock(msg) - close - end + # this is Revactor implementation dependent + msg = Error.response(e) and + client.instance_eval { @_io.write_nonblock(msg) } rescue - nil end def revactorize_listeners! -- cgit v1.2.3-24-ge0c7