aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-10-07 04:30:08 +1030
committerGitHub <noreply@github.com>2016-10-07 04:30:08 +1030
commit3a11c5b626fcd781e3bacd4a59003465e9aafb5f (patch)
treec10152a9433d2a0f419b0620d19b146005b31958 /actioncable
parentfd9abbc4461021d8bed72f5a34745a8271f02d85 (diff)
parent1fe967d0c954f96476c471ee39455d8cceee3061 (diff)
downloadrails-3a11c5b626fcd781e3bacd4a59003465e9aafb5f.tar.gz
rails-3a11c5b626fcd781e3bacd4a59003465e9aafb5f.tar.bz2
rails-3a11c5b626fcd781e3bacd4a59003465e9aafb5f.zip
Merge pull request #26714 from matthewd/close-race
Work around read/close race (x2)
Diffstat (limited to 'actioncable')
-rw-r--r--actioncable/lib/action_cable/connection/stream.rb1
-rw-r--r--actioncable/lib/action_cable/connection/stream_event_loop.rb1
-rw-r--r--actioncable/test/client_test.rb7
-rw-r--r--actioncable/test/connection/client_socket_test.rb12
4 files changed, 11 insertions, 10 deletions
diff --git a/actioncable/lib/action_cable/connection/stream.rb b/actioncable/lib/action_cable/connection/stream.rb
index d66e1b4e41..e620b93845 100644
--- a/actioncable/lib/action_cable/connection/stream.rb
+++ b/actioncable/lib/action_cable/connection/stream.rb
@@ -106,7 +106,6 @@ module ActionCable
def clean_rack_hijack
return unless @rack_hijack_io
@event_loop.detach(@rack_hijack_io, self)
- @rack_hijack_io.close
@rack_hijack_io = nil
end
end
diff --git a/actioncable/lib/action_cable/connection/stream_event_loop.rb b/actioncable/lib/action_cable/connection/stream_event_loop.rb
index eec24638b6..2d1af0ff9f 100644
--- a/actioncable/lib/action_cable/connection/stream_event_loop.rb
+++ b/actioncable/lib/action_cable/connection/stream_event_loop.rb
@@ -36,6 +36,7 @@ module ActionCable
@todo << lambda do
@nio.deregister io
@map.delete io
+ io.close
end
wakeup
end
diff --git a/actioncable/test/client_test.rb b/actioncable/test/client_test.rb
index f6d4ab3202..db10a7ad16 100644
--- a/actioncable/test/client_test.rb
+++ b/actioncable/test/client_test.rb
@@ -21,13 +21,6 @@ WebSocket::Frame::Data.prepend Module.new {
super
end
}
-
-WebSocket::Client::Simple::Client.prepend Module.new {
- def initialize(*)
- @socket = nil
- super
- end
-}
#
####
diff --git a/actioncable/test/connection/client_socket_test.rb b/actioncable/test/connection/client_socket_test.rb
index dff7fefbfb..bc3ff6a3d7 100644
--- a/actioncable/test/connection/client_socket_test.rb
+++ b/actioncable/test/connection/client_socket_test.rb
@@ -51,10 +51,12 @@ class ActionCable::Connection::ClientSocketTest < ActionCable::TestCase
connection = open_connection
client = connection.websocket.send(:websocket)
+ event = Concurrent::Event.new
client.instance_variable_get("@stream")
.instance_variable_get("@rack_hijack_io")
- .expects(:close)
+ .define_singleton_method(:close) { event.set }
connection.close
+ event.wait
end
end
@@ -63,7 +65,13 @@ class ActionCable::Connection::ClientSocketTest < ActionCable::TestCase
env = Rack::MockRequest.env_for "/test",
"HTTP_CONNECTION" => "upgrade", "HTTP_UPGRADE" => "websocket",
"HTTP_HOST" => "localhost", "HTTP_ORIGIN" => "http://rubyonrails.com"
- env["rack.hijack"] = -> { env["rack.hijack_io"] = StringIO.new }
+ io = \
+ begin
+ Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM, 0).first
+ rescue
+ StringIO.new
+ end
+ env["rack.hijack"] = -> { env["rack.hijack_io"] = io }
Connection.new(@server, env).tap do |connection|
connection.process