File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
lib/action_cable/connection Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change 1+ * Protect against concurrent writes to a websocket connection from
2+ multiple threads; the underlying OS write is not always threadsafe.
3+
4+ * Tinco Andringa*
5+
6+
17## Rails 5.0.0 (June 30, 2016) ##
28
39* Fix development reloading support: new cable connections are now correctly
Original file line number Diff line number Diff line change 1+ require 'thread'
2+
13module ActionCable
24 module Connection
35 #--
@@ -11,6 +13,7 @@ def initialize(event_loop, socket)
1113 @stream_send = socket . env [ 'stream.send' ]
1214
1315 @rack_hijack_io = nil
16+ @write_lock = Mutex . new
1417 end
1518
1619 def each ( &callback )
@@ -27,8 +30,10 @@ def shutdown
2730 end
2831
2932 def write ( data )
30- return @rack_hijack_io . write ( data ) if @rack_hijack_io
31- return @stream_send . call ( data ) if @stream_send
33+ @write_lock . synchronize do
34+ return @rack_hijack_io . write ( data ) if @rack_hijack_io
35+ return @stream_send . call ( data ) if @stream_send
36+ end
3237 rescue EOFError , Errno ::ECONNRESET
3338 @socket_object . client_gone
3439 end
You can’t perform that action at this time.
0 commit comments