From dcf96b79a6b1f8d65077ed09b57aff75ba214c91 Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Sat, 1 Jun 2013 14:20:45 -0700 Subject: [PATCH] Handle all read exceptions properly. Fixes #252 --- lib/puma/client.rb | 7 +++++++ lib/puma/server.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/puma/client.rb b/lib/puma/client.rb index ff22bf47..ae9e7ca4 100644 --- a/lib/puma/client.rb +++ b/lib/puma/client.rb @@ -16,6 +16,9 @@ if Puma::IS_JRUBY end module Puma + + class ConnectionError < RuntimeError; end + class Client include Puma::Const @@ -139,6 +142,8 @@ module Puma data = @io.read_nonblock(CHUNK_SIZE) rescue Errno::EAGAIN return false + rescue SystemCallError, IOError + raise ConnectionError, "Connection error detected during read" end if @buffer @@ -223,6 +228,8 @@ module Puma chunk = @io.read_nonblock(want) rescue Errno::EAGAIN return false + rescue SystemCallError, IOError + raise ConnectionError, "Connection error detected during read" end # No chunk means a closed socket diff --git a/lib/puma/server.rb b/lib/puma/server.rb index f3bc6b77..72b23857 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -135,7 +135,7 @@ module Puma client.close @events.parse_error self, client.env, e - rescue IOError + rescue ConnectionError client.close else if process_now