aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/action_cable/connection
diff options
context:
space:
mode:
authorTinco Andringa <mail@tinco.nl>2016-07-01 15:29:29 +0200
committerTinco Andringa <mail@tinco.nl>2016-07-01 15:29:29 +0200
commitce5f9bb2a5b869ae40352f5156d230a7779f896e (patch)
tree8e2c58d10d873251b8296ec772c5e72946b308b0 /actioncable/lib/action_cable/connection
parent49a881e0db1ef64fcbae2b7ddccfd5ccea26ae01 (diff)
downloadrails-ce5f9bb2a5b869ae40352f5156d230a7779f896e.tar.gz
rails-ce5f9bb2a5b869ae40352f5156d230a7779f896e.tar.bz2
rails-ce5f9bb2a5b869ae40352f5156d230a7779f896e.zip
fix race condition in websocket stream write
Diffstat (limited to 'actioncable/lib/action_cable/connection')
-rw-r--r--actioncable/lib/action_cable/connection/stream.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/actioncable/lib/action_cable/connection/stream.rb b/actioncable/lib/action_cable/connection/stream.rb
index 0cf59091bc..91ed81e812 100644
--- a/actioncable/lib/action_cable/connection/stream.rb
+++ b/actioncable/lib/action_cable/connection/stream.rb
@@ -11,6 +11,7 @@ module ActionCable
@stream_send = socket.env['stream.send']
@rack_hijack_io = nil
+ @write_lock = Mutex.new
end
def each(&callback)
@@ -27,10 +28,13 @@ module ActionCable
end
def write(data)
+ @write_lock.lock
return @rack_hijack_io.write(data) if @rack_hijack_io
return @stream_send.call(data) if @stream_send
rescue EOFError, Errno::ECONNRESET
@socket_object.client_gone
+ ensure
+ @write_lock.unlock
end
def receive(data)