diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-12-05 14:29:52 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-05 14:29:52 -0500 |
commit | d9816546494f66e76bd5012a91b872dc2096a06c (patch) | |
tree | 152ca7fc5496aedffeea9633c2c6a71a2c0fbfd3 /actioncable/lib/action_cable | |
parent | 884310fdd031ed8121944f9ea07c8b7723c4e6b6 (diff) | |
parent | 58dbc1c2ed0e372d9cae4c9e3baebb679a726dc3 (diff) | |
download | rails-d9816546494f66e76bd5012a91b872dc2096a06c.tar.gz rails-d9816546494f66e76bd5012a91b872dc2096a06c.tar.bz2 rails-d9816546494f66e76bd5012a91b872dc2096a06c.zip |
Merge pull request #34194 from staugaard/staugaard/actioncable_unauthorized
Stop trying to reconnect on unauthorized cable connections
Diffstat (limited to 'actioncable/lib/action_cable')
-rw-r--r-- | actioncable/lib/action_cable/connection/base.rb | 11 | ||||
-rw-r--r-- | actioncable/lib/action_cable/server/base.rb | 4 |
2 files changed, 11 insertions, 4 deletions
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 |