about summary refs log tree commit homepage
path: root/lib/rainbows/base.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/base.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/base.rb')
-rw-r--r--lib/rainbows/base.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb
index 9a653ff..4be37f4 100644
--- a/lib/rainbows/base.rb
+++ b/lib/rainbows/base.rb
@@ -10,10 +10,9 @@ module Rainbows
     include Rainbows::Const
     G = Rainbows::G
 
-    def listen_loop_error(e)
-      G.alive or return
-      logger.error "Unhandled listen loop exception #{e.inspect}."
-      logger.error e.backtrace.join("\n")
+    def handle_error(client, e)
+      msg = Error.response(e) and client.write_nonblock(msg)
+      rescue
     end
 
     def init_worker_process(worker)
@@ -40,7 +39,7 @@ module Rainbows
 
       begin # loop
         while ! hp.headers(env, buf)
-          IO.select([client], nil, nil, G.kato) or return client.close
+          IO.select([client], nil, nil, G.kato) or return
           buf << client.readpartial(CHUNK_SIZE)
         end
 
@@ -60,13 +59,14 @@ 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
     # if we get any error, try to write something back to the client
     # assuming we haven't closed the socket, but don't get hung up
     # if the socket is already closed or broken.  We'll always ensure
     # the socket is closed at the end of this function
     rescue => e
       handle_error(client, e)
+    ensure
+      client.close
     end
 
     def join_threads(threads)