writer_thread_spawn: worker_connections limits thread spawned
[rainbows.git] / lib / rainbows / error.rb
blobd90dad06bb2dc82f29beef0bfa4797c69cdb5276
1 # -*- encoding: binary -*-
2 module Rainbows
4   class Error
5     class << self
7       # if we get any error, try to write something back to the client
8       # assuming we haven't closed the socket, but don't get hung up
9       # if the socket is already closed or broken.  We'll always ensure
10       # the socket is closed at the end of this function
11       def write(io, e)
12         msg = Error.response(e) and io.write_nonblock(msg)
13         rescue
14       end
16       def app(e)
17         G.server.logger.error "app error: #{e.inspect}"
18         G.server.logger.error e.backtrace.join("\n")
19         rescue
20       end
22       def listen_loop(e)
23         G.alive or return
24         G.server.logger.error "listen loop error: #{e.inspect}."
25         G.server.logger.error e.backtrace.join("\n")
26         rescue
27       end
29       def response(e)
30         case e
31         when EOFError, Errno::ECONNRESET, Errno::EPIPE, Errno::EINVAL,
32              Errno::EBADF, Errno::ENOTCONN
33           # swallow error if client shuts down one end or disconnects
34         when Unicorn::HttpParserError
35           Const::ERROR_400_RESPONSE # try to tell the client they're bad
36         when IOError # HttpParserError is an IOError
37         else
38           app(e)
39           Const::ERROR_500_RESPONSE
40         end
41       end
43     end
44   end
45 end