diff options
author | Jon Moss <me@jonathanmoss.me> | 2016-02-24 21:48:59 -0500 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2016-02-24 21:48:59 -0500 |
commit | a536cc8f1e31e09526b6b43c07ec255d66cd2049 (patch) | |
tree | 43c52cc9a4b8472ce3846e86361b5b15c8875a4d /actioncable/lib/action_cable | |
parent | 8db771bb6977b83408317b6588967d288f5a44cc (diff) | |
download | rails-a536cc8f1e31e09526b6b43c07ec255d66cd2049.tar.gz rails-a536cc8f1e31e09526b6b43c07ec255d66cd2049.tar.bz2 rails-a536cc8f1e31e09526b6b43c07ec255d66cd2049.zip |
Only hijack Rack socket when first needed
Fixes #23471
Diffstat (limited to 'actioncable/lib/action_cable')
-rw-r--r-- | actioncable/lib/action_cable/connection/client_socket.rb | 1 | ||||
-rw-r--r-- | actioncable/lib/action_cable/connection/stream.rb | 18 |
2 files changed, 9 insertions, 10 deletions
diff --git a/actioncable/lib/action_cable/connection/client_socket.rb b/actioncable/lib/action_cable/connection/client_socket.rb index 95e1ac4c16..d7632b05fe 100644 --- a/actioncable/lib/action_cable/connection/client_socket.rb +++ b/actioncable/lib/action_cable/connection/client_socket.rb @@ -58,6 +58,7 @@ module ActionCable def start_driver return if @driver.nil? || @driver_started + @stream.hijack_rack_socket @driver_started = true @driver.start end diff --git a/actioncable/lib/action_cable/connection/stream.rb b/actioncable/lib/action_cable/connection/stream.rb index ace250cd16..2d97b28c09 100644 --- a/actioncable/lib/action_cable/connection/stream.rb +++ b/actioncable/lib/action_cable/connection/stream.rb @@ -4,15 +4,13 @@ module ActionCable # This class is heavily based on faye-websocket-ruby # # Copyright (c) 2010-2015 James Coglan - class Stream + class Stream # :nodoc: def initialize(event_loop, socket) @event_loop = event_loop @socket_object = socket @stream_send = socket.env['stream.send'] @rack_hijack_io = nil - - hijack_rack_socket end def each(&callback) @@ -39,16 +37,16 @@ module ActionCable @socket_object.parse(data) end - private - def hijack_rack_socket - return unless @socket_object.env['rack.hijack'] + def hijack_rack_socket + return unless @socket_object.env['rack.hijack'] - @socket_object.env['rack.hijack'].call - @rack_hijack_io = @socket_object.env['rack.hijack_io'] + @socket_object.env['rack.hijack'].call + @rack_hijack_io = @socket_object.env['rack.hijack_io'] - @event_loop.attach(@rack_hijack_io, self) - end + @event_loop.attach(@rack_hijack_io, self) + end + private def clean_rack_hijack return unless @rack_hijack_io @event_loop.detach(@rack_hijack_io, self) |