Skip to content

Commit 0eadf6b

Browse files
author
Carlos Requena López
committed
[Fix webpack#1616] Exponential reconnect time when connection fails
1 parent 419f02e commit 0eadf6b

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

client-src/default/socket.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
const SockJS = require('sockjs-client/dist/sockjs');
44

5+
// retries variable must increment after each failed reconnection.
6+
// reconnect time depends on it
7+
// See https://github.com/webpack/webpack-dev-server/pull/1617
58
let retries = 0;
69
let sock = null;
710

811
const socket = function initSocket(url, handlers) {
912
sock = new SockJS(url);
1013

11-
sock.onopen = function onopen() {
12-
retries = 0;
13-
};
14+
sock.onopen = function onopen() {};
1415

1516
sock.onclose = function onclose() {
1617
if (retries === 0) {

test/Socket.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const request = require('supertest');
44
const config = require('./fixtures/simple-config/webpack.config');
55
const helper = require('./helper');
6+
const socket = require('../client-src/default/socket.js');
67

78
describe('socket options', () => {
89
let server;
@@ -28,6 +29,23 @@ describe('socket options', () => {
2829
});
2930
});
3031

32+
describe('failing behaviour', () => {
33+
beforeEach((done) => {
34+
server = helper.start(config, {}, done);
35+
req = request('http://localhost:8080');
36+
});
37+
38+
it('should increase reconnect time exponentially', () => {
39+
// TODO
40+
// Try to connect to websocket server, ideally with a different
41+
// origin so it fails to connect
42+
socket("http://localhost:8080/sockjs-node/123/456/websocket");
43+
// Inspect socket (retries or retryInMs) to make sure it waits
44+
// an exponential amount of time and retries variable increases
45+
// every time
46+
});
47+
});
48+
3149
describe('socksPath option', () => {
3250
const path = '/foo/test/bar';
3351
beforeEach((done) => {

0 commit comments

Comments
 (0)