From ce5f9bb2a5b869ae40352f5156d230a7779f896e Mon Sep 17 00:00:00 2001 From: Tinco Andringa Date: Fri, 1 Jul 2016 15:29:29 +0200 Subject: fix race condition in websocket stream write --- actioncable/lib/action_cable/connection/stream.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actioncable/lib/action_cable/connection/stream.rb') 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) -- cgit v1.2.3