From f29a14207aa3084cb2f0a73cb5672729aa0c6d62 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 25 Mar 2015 13:35:01 -0500 Subject: Close the websocket on exception --- lib/action_cable/server.rb | 6 ++++++ lib/action_cable/worker.rb | 9 +++++++++ 2 files changed, 15 insertions(+) (limited to 'lib/action_cable') diff --git a/lib/action_cable/server.rb b/lib/action_cable/server.rb index 77010071d2..ebf98171c1 100644 --- a/lib/action_cable/server.rb +++ b/lib/action_cable/server.rb @@ -99,6 +99,12 @@ module ActionCable self.class.worker_pool end + def handle_exception + logger.error "[ActionCable] Closing connection" + + @websocket.close + end + private def initialize_client connect if respond_to?(:connect) diff --git a/lib/action_cable/worker.rb b/lib/action_cable/worker.rb index 6687af43a0..6773535afe 100644 --- a/lib/action_cable/worker.rb +++ b/lib/action_cable/worker.rb @@ -9,6 +9,11 @@ module ActionCable run_callbacks :work do receiver.send method, *args end + rescue Exception => e + logger.error "[ActionCable] There was an exception - #{e.class}(#{e.message})" + logger.error e.backtrace.join("\n") + + receiver.handle_exception if receiver.respond_to?(:handle_exception) end def run_periodic_timer(channel, callback) @@ -17,5 +22,9 @@ module ActionCable end end + private + def logger + ActionCable::Server.logger + end end end -- cgit v1.2.3