Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Fix race condition in websocket stream write #25624
It is not safe to write to a socket from two threads at the same time. If multiple threads are spawned that perform
This patch simply puts a write lock around the socket so it can never be called concurrently. I don't expect this will not have any significant performance overhead.
I also put the lock around stream_send, though I'm not 100% certain this is also necessary.
Do you require tests for concurrency problems like this?
To reproduce the error, clone this repository: https://github.com/phusion/actioncable-slow-client, run it in Passenger using
p.s.: really sorry that we started performance tests so late, I actually started this on Tuesday thinking I'd make sure Passenger works correctly with Rails 5rc2 but we didn't figure out what was going on until today.
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @kaspth (or someone else) soon.
If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.
Please see the contribution instructions for more information.
Alright, so I was a little curious why this happens so I browsed through ruby/ruby's
I'm not sure why this particular test I did makes it break so reliably, but there you have it.
I guess it might be up to discussion whether Rails should allow ActionCable.server.transmit to be called from different threads, is that something you guys are opinionated on?