Skip to content

Commit 560ebd8

Browse files
committed
17.2.0 - Bump ws dependency
1 parent c48d21e commit 560ebd8

File tree

4 files changed

+72
-22
lines changed

4 files changed

+72
-22
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
"sc-formatter": "^3.0.3",
1919
"stream-demux": "^8.0.0",
2020
"writable-consumable-stream": "^2.0.0",
21-
"ws": "^7.4.6"
21+
"ws": "^8.9.0"
2222
},
2323
"devDependencies": {
2424
"localStorage": "^1.0.3",
2525
"mocha": "^9.0.0",
26-
"socketcluster-client": "^17.0.0"
26+
"socketcluster-client": "^17.1.0"
2727
},
2828
"scripts": {
2929
"test": "mocha --reporter spec --timeout 3000 --slow 3000"

server.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ AGServer.prototype._handleSocketConnection = function (wsSocket, upgradeReq) {
239239
this.emit('handshake', {socket: agSocket});
240240
};
241241

242-
AGServer.prototype.close = function () {
242+
AGServer.prototype.close = function (keepSocketsOpen) {
243243
this.isReady = false;
244244
return new Promise((resolve, reject) => {
245245
this.wsServer.close((err) => {
@@ -249,6 +249,11 @@ AGServer.prototype.close = function () {
249249
}
250250
resolve();
251251
});
252+
if (!keepSocketsOpen) {
253+
for (let socket of Object.values(this.clients)) {
254+
socket.terminate();
255+
}
256+
}
252257
});
253258
};
254259

serversocket.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ function AGServerSocket(id, server, socket, protocolVersion) {
8888
this.emitError(err);
8989
});
9090

91-
this.socket.on('close', (code, reason) => {
91+
this.socket.on('close', (code, reasonBuffer) => {
92+
let reason = reasonBuffer.toString();
9293
this._destroy(code, reason);
9394
});
9495

@@ -127,7 +128,8 @@ function AGServerSocket(id, server, socket, protocolVersion) {
127128
this._handleOutboundPacketStream();
128129

129130
// Receive incoming raw messages
130-
this.socket.on('message', async (message, flags) => {
131+
this.socket.on('message', async (messageBuffer, isBinary) => {
132+
let message = isBinary ? messageBuffer : messageBuffer.toString();
131133
this.inboundReceivedMessageCount++;
132134

133135
let isPong = message === pongMessage;

test/integration.js

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,7 +2568,7 @@ describe('Integration tests', function () {
25682568
});
25692569

25702570
describe('Socket Ping/pong', function () {
2571-
describe('When when pingTimeoutDisabled is not set', function () {
2571+
describe('When pingTimeoutDisabled is not set', function () {
25722572
beforeEach('Launch server with ping options before start', async function () {
25732573
// Intentionally make pingInterval higher than pingTimeout, that
25742574
// way the client will never receive a ping or send back a pong.
@@ -2628,7 +2628,7 @@ describe('Integration tests', function () {
26282628
});
26292629
});
26302630

2631-
describe('When when pingTimeoutDisabled is true', function () {
2631+
describe('When pingTimeoutDisabled is true', function () {
26322632
beforeEach('Launch server with ping options before start', async function () {
26332633
// Intentionally make pingInterval higher than pingTimeout, that
26342634
// way the client will never receive a ping or send back a pong.
@@ -2687,12 +2687,67 @@ describe('Integration tests', function () {
26872687
assert.equal(serverDisconnectionCode, null);
26882688
});
26892689
});
2690+
2691+
describe('When pingTimeout is greater than pingInterval', function () {
2692+
beforeEach('Launch server with ping options before start', async function () {
2693+
// Intentionally make pingInterval higher than pingTimeout, that
2694+
// way the client will never receive a ping or send back a pong.
2695+
server = socketClusterServer.listen(PORT_NUMBER, {
2696+
authKey: serverOptions.authKey,
2697+
wsEngine: WS_ENGINE,
2698+
pingInterval: 400,
2699+
pingTimeout: 1000
2700+
});
2701+
bindFailureHandlers(server);
2702+
2703+
await server.listener('ready').once();
2704+
});
2705+
2706+
it('Should not disconnect socket if server receives a pong from client before timeout', async function () {
2707+
client = socketClusterClient.create({
2708+
hostname: clientOptions.hostname,
2709+
port: PORT_NUMBER
2710+
});
2711+
2712+
let serverWarning = null;
2713+
(async () => {
2714+
for await (let {warning} of server.listener('warning')) {
2715+
serverWarning = warning;
2716+
}
2717+
})();
2718+
2719+
let serverDisconnectionCode = null;
2720+
(async () => {
2721+
for await (let event of server.listener('disconnection')) {
2722+
serverDisconnectionCode = event.code;
2723+
}
2724+
})();
2725+
2726+
let clientError = null;
2727+
(async () => {
2728+
for await (let {error} of client.listener('error')) {
2729+
clientError = error;
2730+
}
2731+
})();
2732+
2733+
let clientDisconnectCode = null;
2734+
(async () => {
2735+
for await (let event of client.listener('disconnect')) {
2736+
clientDisconnectCode = event.code;
2737+
}
2738+
})();
2739+
2740+
await wait(2000);
2741+
assert.equal(clientError, null);
2742+
assert.equal(clientDisconnectCode, null);
2743+
2744+
assert.equal(serverWarning, null);
2745+
assert.equal(serverDisconnectionCode, null);
2746+
});
2747+
});
26902748
});
26912749

26922750
describe('Middleware', function () {
2693-
let server;
2694-
let client;
2695-
26962751
beforeEach('Launch server without middleware before start', async function () {
26972752
server = socketClusterServer.listen(PORT_NUMBER, {
26982753
authKey: serverOptions.authKey,
@@ -2709,18 +2764,6 @@ describe('Integration tests', function () {
27092764
await server.listener('ready').once();
27102765
});
27112766

2712-
afterEach('Close server after each middleware test', async function () {
2713-
if (client) {
2714-
client.closeAllListeners();
2715-
client.disconnect();
2716-
}
2717-
if (server) {
2718-
server.closeAllListeners();
2719-
server.httpServer.close();
2720-
await server.close();
2721-
}
2722-
});
2723-
27242767
describe('MIDDLEWARE_HANDSHAKE', function () {
27252768
describe('HANDSHAKE_WS action', function () {
27262769
it('Delaying handshake for one client should not affect other clients', async function () {

0 commit comments

Comments
 (0)