6451: Don't crash on ArgumentError. Add test to verify that it doesn't crash.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Thu, 23 Jul 2015 16:17:40 +0000 (12:17 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Thu, 23 Jul 2015 16:17:40 +0000 (12:17 -0400)
services/api/lib/eventbus.rb
services/api/test/integration/websocket_test.rb

index 35671d65b287e495a76b2fc94b47cdf588983350..d32e150ffe700565b4238cf1280ccfd152620ecb 100644 (file)
@@ -140,10 +140,15 @@ class EventBus
         # No filters set up, so just record the sequence number
         ws.last_log_id = notify_id
       end
+    rescue ArgumentError => e
+      # There was some kind of user error.
+      Rails.logger.warn "Error publishing event: #{$!}"
+      ws.send ({status: 500, message: $!}.to_json)
+      ws.close
     rescue => e
       Rails.logger.warn "Error publishing event: #{$!}"
       Rails.logger.warn "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
-      ws.send ({status: 500, message: 'error'}.to_json)
+      ws.send ({status: 500, message: $!}.to_json)
       ws.close
       # These exceptions typically indicate serious server trouble:
       # out of memory issues, database connection problems, etc.  Go ahead and
index 9179acd6803fa2fcb0384a507103b9bf390a5d15..a4133ba5fee9878f29df3ba34ce19d247842dd30 100644 (file)
@@ -646,4 +646,55 @@ class WebsocketTest < ActionDispatch::IntegrationTest
   end
 
 
+  test "connect, subscribe with invalid filter" do
+    state = 1
+    human = nil
+    human_ev_uuid = nil
+
+    authorize_with :admin
+
+    ws_helper :admin do |ws|
+      ws.on :open do |event|
+        ws.send ({method: 'subscribe', filters: [['object_blarg', 'is_a', 'arvados#human']]}.to_json)
+      end
+
+      ws.on :message do |event|
+        d = Oj.load event.data
+        case state
+        when 1
+          assert_equal 200, d["status"]
+          Specimen.create
+          human = Human.create
+          state = 2
+        when 2
+          assert_equal 500, d["status"]
+          state = 3
+          ws.close
+        when 3
+          assert false, "Should not get any more events"
+        end
+      end
+
+    end
+
+    # Try connecting again, test that #6451 is fixed
+    # (invalid filter crashes websockets)
+    status = nil
+    ws_helper :admin do |ws|
+      ws.on :open do |event|
+        ws.send ({method: 'subscribe'}.to_json)
+      end
+
+      ws.on :message do |event|
+        d = Oj.load event.data
+        status = d["status"]
+        ws.close
+      end
+    end
+
+    assert_equal 200, status
+
+  end
+
+
 end