-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the upgradeReq
property
#1099
Conversation
2236ed9
to
d895a47
Compare
Remove unnecessary events
This is a major breaking change tho. |
This is indeed a big change. It will break a lot of existing code, but along with nodejs/node#11926 will greatly reduce memory usage. In the worst case scenario all is needed to bring back the old behavior is this: wss.on('connection', (ws, req) => {
ws.upgradeReq = req;
}); Currently the opposite is needed to free the memory. wss.on('connection', (ws) => {
ws.upgradeReq = null;
}); Basically it will make the feature opt-in instead of opt-out. |
The `http.IncomingMessage` object, instead of being attached to the `WebSocket` object, is passes as the second argument to the `connection` event.
d895a47
to
824be55
Compare
Ops, I deleted the branch instead of force pushing 😄. |
Summary: Address the breaking changes from: https://github.com/websockets/ws/releases/tag/3.0.0 Apply the changes suggested in websockets/ws#1099 Apply the changes suggested in websockets/ws#1101 Reviewed By: hansonw Differential Revision: D6031593 fbshipit-source-id: 6ffe8b03dd6ddab1dc26074a5d9b3baf55689d17
To reduce memory usage ws replaced the socket.updateReq property with 2nd argument to the connection event [1] [1] websockets/ws#1099
To reduce memory usage ws replaced the socket.updateReq property with 2nd argument to the connection event [1] [1] websockets/ws#1099
To reduce memory usage ws replaced the socket.updateReq property with 2nd argument to the connection event [1] [1] websockets/ws#1099
Hi Where is sec-websocket-key |
@projetoarduino in the wss.on('connection', (ws, req) => {
const key = req.headers['sec-websocket-key'];
}); |
Thanks my friend. |
Hi, this method work, but i need one unique id per client. Answering my own question: The way I managed to identify the clients was this ws._ultron.id |
Hey @projetoarduino |
Hi use wss.clients.forEach but add one 'if' to compare and send only client you need.
|
Don't use private properties as they may disappear at any time. If you need a unique id per connection generate it. wss.on('connection', (ws) => {
ws.id = uuid();
}); |
an optimization in version 3.0 of the required proxy server [ websockets/ws#1114 ]drops the upgradeReq parameter to save 20% in memory. This breaks non-http(s) requests that use upgrade to switch - like web sockets (ws and wss). This was never a consideration for he mitm proxy (I guess since the package specifies version 3.2 and up - so it never worked). This matters for me so we re include it per the recommendation from the package maintainers [ websockets/ws#1099 ]
@lpinca Thanks, i tested this and work fine. |
ws 3 removed upgradeReq property: websockets/ws#1099 this is now a second argument to the connection callback i.e. wss.on('connection', function(ws, req){...
ws 3 removed upgradeReq property: websockets/ws#1099 this is now a second argument to the connection callback i.e. wss.on('connection', function(ws, req){...
Get it in the new way, from the connection event: websockets/ws#1099
…q support BREAKING: Drop old Edge - Non Chromium versions of Edge are no longer supported BREAKING: Drop Node 10 server support - If you use require('simple-websocket/server') then we require Node 12 minmum for ES class property syntax. If you need earlier Node support, then continue relying on the last major version. BREAKING: Remove upgradeReq support - upgradeReq was removed from ws in an earlier version. See websockets/ws#1099 for how to re-add it back if it's needed Server: Pass options through to SimpleWebSocket constructor - For example, a server can be initialized with server = new Server({ port, encoding: 'utf8' }) to make each connection stream use utf8 encoding
Summary: # Context #674 >There is a security vulnerability with the current version of ws, that requires it to be upgraded to 5.2.3. # In this diff > At a glance, we're affected by at least websockets/ws#1099 in v3.x (here) and websockets/ws@63e275e in v4.x (here). Probably a few other changes as well. Like motiz88 mentioned in the issue, there's only 2 API changes that needed to be fixed: - `upgradeReq` was removed from the web socket object, the fix being to take the URL from the request param instead - `onError` now correctly passes an `ErrorEvent` instead of an `Error` object Those are the only usages of ws in metro that i've seen Reviewed By: GijsWeterings Differential Revision: D29517185 fbshipit-source-id: bac12e7106f09b88877e2e138472a0d981d55200
There was one breaking change but didn't end up being that big of a deal. websockets/ws#1099
This removes the
upgradeReq
property from theWebSocket
object. Thehttp.IncomingMessage
object is instead passed as the second argument to theconnection
event.In this way most of the memory retained by the
http.IncomingMessage
object can be GC'ed reducing memory usage by ~20%.Developers can save only the required info or the whole
http.IncomingMessage
object, if they have to, when the event is emitted.