about summary refs log tree commit homepage
path: root/lib/mogilefs/backend.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mogilefs/backend.rb')
-rw-r--r--lib/mogilefs/backend.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb
index a6b5e93..f611cbd 100644
--- a/lib/mogilefs/backend.rb
+++ b/lib/mogilefs/backend.rb
@@ -229,11 +229,15 @@ class MogileFS::Backend
   def do_request(cmd, args, idempotent = false)
     no_raise = args.delete(:ruby_no_raise)
     request = make_request(cmd, args)
+    line = nil
     @mutex.synchronize do
       begin
         io = dispatch_unlocked(request)
-        line = io.timed_gets(@timeout) and
-          return parse_response(line, no_raise ? request : nil)
+        line = io.timed_gets(@timeout)
+        break if /\r?\n\z/ =~ line
+
+        line and raise MogileFS::InvalidResponseError,
+                       "Invalid response from server: #{line.inspect}"
 
         idempotent or
           raise EOFError, "end of file reached after: #{request.inspect}"
@@ -252,6 +256,7 @@ class MogileFS::Backend
         shutdown_unlocked(true)
       end while idempotent
     end # @mutex.synchronize
+    parse_response(line, no_raise ? request : nil)
   end
 
   # Makes a new request string for +cmd+ and +args+.