about summary refs log tree commit homepage
path: root/lib/rainbows/revactor.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-26 14:09:45 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-26 14:19:04 -0800
commit5868eeecb2fbc85f3e4fabf3d16f27d259491c0d (patch)
tree21746be61158f9c177bc8e2600d7922cdedc7ce1 /lib/rainbows/revactor.rb
parent278d9d5a7f3d2dc3c6563af1584b5e773e08073d (diff)
downloadrainbows-5868eeecb2fbc85f3e4fabf3d16f27d259491c0d.tar.gz
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.
Diffstat (limited to 'lib/rainbows/revactor.rb')
-rw-r--r--lib/rainbows/revactor.rb27
1 files changed, 7 insertions, 20 deletions
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!