Skip to content

Commit 39a69c3

Browse files
abcanghiyuki2578
authored andcommitted
Migrate from uws to cws (mastodon#10805)
1 parent 1b77c01 commit 39a69c3

3 files changed

Lines changed: 11 additions & 28 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "mastodon",
33
"license": "AGPL-3.0-or-later",
44
"engines": {
5-
"node": ">=8 <11"
5+
"node": ">=8.12 <12"
66
},
77
"scripts": {
88
"postversion": "git push --tags",
@@ -69,6 +69,7 @@
6969
"@babel/preset-env": "^7.3.4",
7070
"@babel/preset-react": "^7.0.0",
7171
"@babel/runtime": "^7.3.4",
72+
"@clusterws/cws": "^0.14.0",
7273
"array-includes": "^3.0.3",
7374
"autoprefixer": "^9.4.10",
7475
"axios": "^0.18.0",
@@ -157,7 +158,6 @@
157158
"tiny-queue": "^0.2.1",
158159
"uglifyjs-webpack-plugin": "^2.1.2",
159160
"uuid": "^3.1.0",
160-
"uws": "10.148.0",
161161
"webpack": "^4.29.6",
162162
"webpack-assets-manifest": "^3.1.1",
163163
"webpack-bundle-analyzer": "^3.1.0",

streaming/index.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const redis = require('redis');
77
const pg = require('pg');
88
const log = require('npmlog');
99
const url = require('url');
10-
const WebSocket = require('uws');
10+
const { WebSocketServer } = require('@clusterws/cws');
1111
const uuid = require('uuid');
1212
const fs = require('fs');
1313

@@ -536,20 +536,13 @@ const startWorker = (workerId) => {
536536
});
537537
});
538538

539-
const wss = new WebSocket.Server({ server, verifyClient: wsVerifyClient });
539+
const wss = new WebSocketServer({ server, verifyClient: wsVerifyClient });
540540

541-
wss.on('connection', ws => {
542-
const req = ws.upgradeReq;
541+
wss.on('connection', (ws, req) => {
543542
const location = url.parse(req.url, true);
544543
req.requestId = uuid.v4();
545544
req.remoteAddress = ws._socket.remoteAddress;
546545

547-
ws.isAlive = true;
548-
549-
ws.on('pong', () => {
550-
ws.isAlive = true;
551-
});
552-
553546
let channel;
554547

555548
switch(location.query.stream) {
@@ -610,17 +603,7 @@ const startWorker = (workerId) => {
610603
}
611604
});
612605

613-
setInterval(() => {
614-
wss.clients.forEach(ws => {
615-
if (ws.isAlive === false) {
616-
ws.terminate();
617-
return;
618-
}
619-
620-
ws.isAlive = false;
621-
ws.ping('', false, true);
622-
});
623-
}, 30000);
606+
wss.startAutoPing(30000);
624607

625608
attachServerWithConfig(server, address => {
626609
log.info(`Worker ${workerId} now listening on ${address}`);

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,11 @@
782782
lodash "^4.17.11"
783783
to-fast-properties "^2.0.0"
784784

785+
"@clusterws/cws@^0.14.0":
786+
version "0.14.0"
787+
resolved "https://registry.yarnpkg.com/@clusterws/cws/-/cws-0.14.0.tgz#242824b6884454001340222a836db6f6c5e62bfb"
788+
integrity sha512-knZj3KZNHIAGsX7TUc/0Q5gcx2bKMMcTPsAOZomLKdK5a4o/umKFlttWRH84Yr1nVlQy+UMO23qfDR8gRZ/4cw==
789+
785790
"@cnakazawa/watch@^1.0.3":
786791
version "1.0.3"
787792
resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.3.tgz#099139eaec7ebf07a27c1786a3ff64f39464d2ef"
@@ -9269,11 +9274,6 @@ uuid@^3.0.1, uuid@^3.1.0, uuid@^3.3.2:
92699274
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
92709275
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==
92719276

9272-
uws@10.148.0:
9273-
version "10.148.0"
9274-
resolved "https://registry.yarnpkg.com/uws/-/uws-10.148.0.tgz#3fcd35f083ca515e091cd33b2d78f0f51a666215"
9275-
integrity sha512-aJpFgMMyxubiE/ll4nj9nWoQbv0HzZZDWXfwyu78nuFObX0Zoyv3TWjkqKPQ1vb2sMPZoz67tri7QNE6dybNmQ==
9276-
92779277
v8-compile-cache@^2.0.2:
92789278
version "2.0.2"
92799279
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.0.2.tgz#a428b28bb26790734c4fc8bc9fa106fccebf6a6c"

0 commit comments

Comments
 (0)