aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2015-03-25 13:35:01 -0500
committerPratik Naik <pratiknaik@gmail.com>2015-03-25 13:35:01 -0500
commitf29a14207aa3084cb2f0a73cb5672729aa0c6d62 (patch)
treed0ba43a358e4c44a13b66c406ddb7e4975df4631 /lib
parent432139183e885f69c6a8f576af7a178842a6e2a1 (diff)
downloadrails-f29a14207aa3084cb2f0a73cb5672729aa0c6d62.tar.gz
rails-f29a14207aa3084cb2f0a73cb5672729aa0c6d62.tar.bz2
rails-f29a14207aa3084cb2f0a73cb5672729aa0c6d62.zip
Close the websocket on exception
Diffstat (limited to 'lib')
-rw-r--r--lib/action_cable/server.rb6
-rw-r--r--lib/action_cable/worker.rb9
2 files changed, 15 insertions, 0 deletions
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