Please sign in to comment.
Begin writing HTTP request headers early to detect disconnected clients
This patch checks incoming connections and avoids calling the application if the connection has been closed. It works by sending the beginning of the HTTP response before calling the application to see if the socket can successfully be written to. By enabling this feature users can avoid wasting application rendering time only to find the connection is closed when attempting to write, and throwing out the result. When a client disconnects while being queued or processed, Nginx will log HTTP response 499 but the application will log a 200. Enabling this feature will minimize the time window during which the problem can arise. The feature is disabled by default and can be enabled by adding 'check_client_connection true' to the unicorn config. [ew: After testing this change, Tom Burns wrote: So we just finished the US Black Friday / Cyber Monday weekend running unicorn forked with the last version of the patch I had sent you. It worked splendidly and helped us handle huge flash sales without increased response time over the weekend. Whereas in previous flash traffic scenarios we would see the number of HTTP 499 responses grow past the number of real HTTP 200 responses, over the weekend we saw no growth in 499s during flash sales. Unexpectedly the patch also helped us ward off a DoS attack where the attackers were disconnecting immediately after making a request. ref: <CAK4qKG3rkfVYLyeqEqQyuNEh_nZ8yw0X_cwTxJfJ+TOU+y8Ffirstname.lastname@example.org> ] Signed-off-by: Eric Wong <email@example.com>
- Loading branch information...
Showing with 116 additions and 10 deletions.
- +6 −0 examples/unicorn.conf.rb
- +3 −1 ext/unicorn_http/unicorn_http.rl
- +25 −0 lib/unicorn/configurator.rb
- +8 −4 lib/unicorn/const.rb
- +19 −0 lib/unicorn/http_request.rb
- +4 −2 lib/unicorn/http_response.rb
- +21 −2 lib/unicorn/http_server.rb
- +6 −1 test/exec/test_exec.rb
- +24 −0 test/unit/test_configurator.rb