aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib
diff options
context:
space:
mode:
authorMick Staugaard <mick@staugaard.com>2018-10-11 13:47:16 -0700
committerMick Staugaard <mick@staugaard.com>2018-12-05 10:40:29 -0800
commit58dbc1c2ed0e372d9cae4c9e3baebb679a726dc3 (patch)
tree9cfd085ce218a95879df56e8008d54978026e134 /actioncable/lib
parentb802e08273f899d5f3b199f7c6a4f5d514c1b0e1 (diff)
downloadrails-58dbc1c2ed0e372d9cae4c9e3baebb679a726dc3.tar.gz
rails-58dbc1c2ed0e372d9cae4c9e3baebb679a726dc3.tar.bz2
rails-58dbc1c2ed0e372d9cae4c9e3baebb679a726dc3.zip
Stop trying to reconnect on unauthorized cable connections
Diffstat (limited to 'actioncable/lib')
-rw-r--r--actioncable/lib/action_cable.rb6
-rw-r--r--actioncable/lib/action_cable/connection/base.rb11
-rw-r--r--actioncable/lib/action_cable/server/base.rb4
3 files changed, 17 insertions, 4 deletions
diff --git a/actioncable/lib/action_cable.rb b/actioncable/lib/action_cable.rb
index d261d4112e..cb9dfa2268 100644
--- a/actioncable/lib/action_cable.rb
+++ b/actioncable/lib/action_cable.rb
@@ -33,10 +33,16 @@ module ActionCable
INTERNAL = {
message_types: {
welcome: "welcome",
+ disconnect: "disconnect",
ping: "ping",
confirmation: "confirm_subscription",
rejection: "reject_subscription"
},
+ disconnect_reasons: {
+ unauthorized: "unauthorized",
+ invalid_request: "invalid_request",
+ server_restart: "server_restart"
+ },
default_mount_path: "/cable",
protocols: ["actioncable-v1-json", "actioncable-unsupported"].freeze
}
diff --git a/actioncable/lib/action_cable/connection/base.rb b/actioncable/lib/action_cable/connection/base.rb
index 11a1f1a5e8..0044afad98 100644
--- a/actioncable/lib/action_cable/connection/base.rb
+++ b/actioncable/lib/action_cable/connection/base.rb
@@ -95,7 +95,12 @@ module ActionCable
end
# Close the WebSocket connection.
- def close
+ def close(reason: nil, reconnect: true)
+ transmit(
+ type: ActionCable::INTERNAL[:message_types][:disconnect],
+ reason: reason,
+ reconnect: reconnect
+ )
websocket.close
end
@@ -170,7 +175,7 @@ module ActionCable
message_buffer.process!
server.add_connection(self)
rescue ActionCable::Connection::Authorization::UnauthorizedError
- respond_to_invalid_request
+ close(reason: ActionCable::INTERNAL[:disconnect_reasons][:unauthorized], reconnect: false) if websocket.alive?
end
def handle_close
@@ -211,7 +216,7 @@ module ActionCable
end
def respond_to_invalid_request
- close if websocket.alive?
+ close(reason: ActionCable::INTERNAL[:disconnect_reasons][:invalid_request]) if websocket.alive?
logger.error invalid_request_message
logger.info finished_request_message
diff --git a/actioncable/lib/action_cable/server/base.rb b/actioncable/lib/action_cable/server/base.rb
index 1ee03f6dfc..2b9e1cba3b 100644
--- a/actioncable/lib/action_cable/server/base.rb
+++ b/actioncable/lib/action_cable/server/base.rb
@@ -36,7 +36,9 @@ module ActionCable
end
def restart
- connections.each(&:close)
+ connections.each do |connection|
+ connection.close(reason: ActionCable::INTERNAL[:disconnect_reasons][:server_restart])
+ end
@mutex.synchronize do
# Shutdown the worker pool