Skip to content
This repository
Browse code

close the response when the response body is set so that normal rende…

…r calls will work
  • Loading branch information...
commit fa3c4ea6d0dee5995d0ac56699540eb9a3149224 1 parent 4509494
Aaron Patterson authored
5  actionpack/lib/action_controller/metal/live.rb
@@ -121,6 +121,11 @@ def process(name)
121 121
       @_response.await_commit
122 122
     end
123 123
 
  124
+    def response_body=(body)
  125
+      super
  126
+      response.stream.close if response
  127
+    end
  128
+
124 129
     def set_response!(request)
125 130
       if request.env["HTTP_VERSION"] == "HTTP/1.0"
126 131
         super
9  actionpack/test/controller/live_stream_test.rb
@@ -12,6 +12,10 @@ def self.controller_path
12 12
         'test'
13 13
       end
14 14
 
  15
+      def render_text
  16
+        render :text => 'zomg'
  17
+      end
  18
+
15 19
       def default_header
16 20
         response.stream.write "<html><body>hi</body></html>"
17 21
         response.stream.close
@@ -107,5 +111,10 @@ def test_live_stream_default_header
107 111
       _, headers, _ = @response.prepare!
108 112
       assert headers['Content-Type']
109 113
     end
  114
+
  115
+    def test_render_text
  116
+      get :render_text
  117
+      assert @response.stream.closed?, 'stream should be closed'
  118
+    end
110 119
   end
111 120
 end

5 notes on commit fa3c4ea

Carlos Antonio da Silva

Hey mate, this test is apparently failing randomly on travis, but it's passing locally for me =(, mind taking a look?

Rafael Mendonça França
Owner

I think is due a race condition. I could reproduce placing a sleep before response.stream.close if response

Aaron Patterson
Owner

Yes, I'll take a look! Thanks

Aaron Patterson
Owner

Should be fixed in c391919

Please sign in to comment.
Something went wrong with that request. Please try again.