FluidFramework icon indicating copy to clipboard operation
FluidFramework copied to clipboard

Upgrade Fluid to latest version of socket.io-client

Open christiango opened this issue 5 years ago • 26 comments

Socket.io released V3 recently. As a consumer of Fluid, I am not looking for any new features, but the new version of socket.io does update the versions of debug and ms that it uses to the latest versions, which makes it compatible with what Fluid Framework already requires.

Upgrading socket IO could resolve #4080

We should also update the duplicate package checker exception in the bundle tests package to remove all the socket.io specific overrides: https://github.com/microsoft/FluidFramework/blob/955a4c77c7c4b29c66572097caf5818983b7ef25/examples/utils/bundle-size-tests/webpack.config.js#L50

christiango avatar Dec 15 '20 20:12 christiango

I tried to make a PR to upgrade, but it seems socket.io is incompatible across client and server with V2/V3 so this required coordination among ODSP and FF.

https://socket.io/docs/v3/migrating-from-2-x-to-3-0/index.html

Perhaps as a part of this conversation, we can discuss if we still need/want to use socket.io rather than a thin layer above native web sockets. It's a heavy library (includes a polyfill for websockets we don't need).

In fact, they even have a whole section calling out what socket.io adds in 2020: https://socket.io/blog/socket-io-3-release/

I wonder how much of that list we actually use.

christiango avatar Dec 15 '20 21:12 christiango

@GaryWilber on thought of getting rid of socket.io

curtisman avatar Jan 08 '21 16:01 curtisman

I'm up for replacing socket.io with something else as long as we find a good alternative. Are there any suggestions? I also imagine we would want alfred to use the same replacement. +@tanviraumi as fyi

In the meantime, there is a way to have the server run socket.io 2 and socket.io 3 in parallel. So we could support a client upgrade to socket.io 3 if that's desirable.

GaryWilber avatar Jan 08 '21 20:01 GaryWilber

From the client perspective, I think we'd want to use native websockets directly to reduce bundle size impact, since socket IO brings in a bunch of other code around falling back to long polling. What else do we need from socket.io from the client perspective? I think there is some notion of rooms, is that available standalone? Can we implement a lightweight version of it ourselves?

@vladsud also had found that our current socket setup is CPU intensive, which is why we defer it to after the initial render. Not sure how much socket.io is to blame here, but it may provide us with an opportunity to improve

christiango avatar Jan 08 '21 20:01 christiango

WebSockets by themselves are pretty barebones. Here are a few things socket.io does for us that we would need to support in a replacement:

  1. Rooms - Rooms is a serverside concept that's used when we want to emit messages to a select group of connections. In our case, we setup a room for each document. That way we can easily broadcast ops to all clients for a document.
  2. PubSub backplane support - In Alfred / Push v2, clients can connect to any document from any frontend machine. Socket.io has support for inserting an "adapter" which allows us to insert Redis into the mix. So when we emit ops to rooms, those ops are broadcasted & received by all relevant frontend machines via Redis.
  3. Connection keep-alive / ping pong - WebSockets don't have a built in mechanism for detecting broken connections. Socket.io solves this by implementing a ping-pong event. Every minute or so the server/client will send a ping-pong event back and forth. The server disconnects the websocket if it hasn't received a reply for some time.

1 & 2 are serverside pieces. 3 is something thing we would need to support in the client and server. We would also need to decide on the message protocol between the client & server (message serialization, chunking, etc). I'm not quite sure how much work this would all be, it should be possible though.

GaryWilber avatar Jan 08 '21 20:01 GaryWilber

I am okay with changing socket.io to something lighter as well. Between Push and alfred, I believe the basic usages of socket.io are very similar. So we can possibly abstract out the core usage and both can benefit by the same code.

This is the lightweight library that I know of (https://github.com/websockets/ws). But lightweight may come with additional code. For the reason Gary already mentioned.

tanviraumi avatar Jan 08 '21 20:01 tanviraumi

I support as well exploring here and improving (as socket.io has a lot of perf problems), but this will take months to make it happen. So we likely want to track it orthogonally from pure upgrade to socket.io V3

vladsud avatar Jan 08 '21 21:01 vladsud

The question is whether we want to upgrade to socket.io V3 at all though? Is there any reason we can't stick with V2 and work on replacing it completely?

curtisman avatar Jan 12 '21 00:01 curtisman

@curtisman @vladsud There is a known security vulnerability with versions of socket.io-client < 3.4.1 that is affecting us because of this dependency

https://github.com/socketio/socket.io-parser/commit/dcb942d24db97162ad16a67c2a0cf30875342d55

jogonzal avatar Mar 03 '21 18:03 jogonzal

@jogonzal The fix for socket.io-parser was backported to 3.3.2: https://github.com/socketio/socket.io-parser/releases/tag/3.3.2. The dependency for socket.io-client 2.4.0 -> socket.io-parser is ~3.3.0. So you should be able to update your lock file to get the security fix.

curtisman avatar Mar 03 '21 19:03 curtisman

Perfect, that is helpful!

jogonzal avatar Mar 03 '21 20:03 jogonzal

@curtisman @vladsud and @GaryWilber : We should also come up with a plan on when to migrate to the simpler library. It will be a very big work item, so we need to get on board with that

tanviraumi avatar Mar 03 '21 21:03 tanviraumi

I totally agree with you, but realistically this is not that high in priority (at least for me). Yes, bundle size is huge, but currently we have a lot of other perf items that are much more important. I guess if we have resources to attack it, sure, but my feeling is that runtime team & Gary will be busy with shipping quality for quite a while (before and after GA of Fluid Experiences)

vladsud avatar Mar 03 '21 21:03 vladsud

Makes sense. I will leave it with you guys to track it, whenever you feel appropriate. My guess (not backed by data) is, it will also reduce server cogs since we will able to serve more connections from a single box.

tanviraumi avatar Mar 04 '21 03:03 tanviraumi

Just want to point out that different driver/service can have use different versions, right? Your team may be possible to do r11s driver first?

curtisman avatar Mar 07 '21 02:03 curtisman

Correct! We are currently collecting data on scale characteristics on FRS. Depending on the outcome, we might want to tackle it sooner. FYI @sharmakhushboo

tanviraumi avatar Mar 08 '21 19:03 tanviraumi

This issue has been automatically marked as stale because it has had no activity for 180 days. It will be closed if no further activity occurs within 8 days of this comment. Thank you for your contributions to Fluid Framework!

ghost avatar Sep 08 '21 03:09 ghost

This issue is still relevant and should not be auto closed

christiango avatar Sep 08 '21 12:09 christiango

r11s is already on socket.io v4 and I believe Push has migrated as well (@znewton and @GaryWilber to confirm).

So we should be in a spot to upgrade the client now.

@jatgarg to check the driver/common code.

tanviraumi avatar Sep 08 '21 17:09 tanviraumi

Yes Push is running socket.io v4

GaryWilber avatar Sep 08 '21 17:09 GaryWilber