diff options
author | Tinco Andringa <mail@tinco.nl> | 2016-07-01 15:29:29 +0200 |
---|---|---|
committer | Tinco Andringa <mail@tinco.nl> | 2016-07-01 15:29:29 +0200 |
commit | ce5f9bb2a5b869ae40352f5156d230a7779f896e (patch) | |
tree | 8e2c58d10d873251b8296ec772c5e72946b308b0 /actioncable/lib/action_cable/connection | |
parent | 49a881e0db1ef64fcbae2b7ddccfd5ccea26ae01 (diff) | |
download | rails-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.rb | 4 |
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) |