aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/action_cable/connection
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-07-09 02:39:44 +0930
committerMatthew Draper <matthew@trebex.net>2016-07-09 02:44:15 +0930
commit92421ee2d234cef370fdbf647a8ae902fc79f5f8 (patch)
treed5e3296d9d9088480f77bbe5b276c08501eb0125 /actioncable/lib/action_cable/connection
parent9c4c2126b1506e2d26107c802a5abba1e6cba886 (diff)
parentce5f9bb2a5b869ae40352f5156d230a7779f896e (diff)
downloadrails-92421ee2d234cef370fdbf647a8ae902fc79f5f8.tar.gz
rails-92421ee2d234cef370fdbf647a8ae902fc79f5f8.tar.bz2
rails-92421ee2d234cef370fdbf647a8ae902fc79f5f8.zip
Merge pull request #25624 from tinco/actioncable_write_race
Fix race condition in websocket stream write
Diffstat (limited to 'actioncable/lib/action_cable/connection')
-rw-r--r--actioncable/lib/action_cable/connection/stream.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/actioncable/lib/action_cable/connection/stream.rb b/actioncable/lib/action_cable/connection/stream.rb
index c250cf92fc..5695623859 100644
--- a/actioncable/lib/action_cable/connection/stream.rb
+++ b/actioncable/lib/action_cable/connection/stream.rb
@@ -1,3 +1,5 @@
+require 'thread'
+
module ActionCable
module Connection
#--
@@ -11,6 +13,7 @@ module ActionCable
@stream_send = socket.env['stream.send']
@rack_hijack_io = nil
+ @write_lock = Mutex.new
end
def each(&callback)
@@ -27,8 +30,10 @@ module ActionCable
end
def write(data)
- return @rack_hijack_io.write(data) if @rack_hijack_io
- return @stream_send.call(data) if @stream_send
+ @write_lock.synchronize do
+ return @rack_hijack_io.write(data) if @rack_hijack_io
+ return @stream_send.call(data) if @stream_send
+ end
rescue EOFError, Errno::ECONNRESET
@socket_object.client_gone
end