Skip to content

Commit fa1fe24

Browse files
Merge pull request #292 from cmu15122/jtromero/working
third time's the charm for sockets?
2 parents 1e2dea4 + 5e0e517 commit fa1fe24

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

DEPLOYMENT.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ server {
7272
proxy_set_header Upgrade $http_upgrade;
7373
proxy_set_header Connection "upgrade";
7474
proxy_set_header Host $host;
75+
proxy_read_timeout 600s;
76+
proxy_send_timeout 600s;
7577
}
7678
}
7779
```

client/src/services/SocketsService.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,24 @@ export const initiateSocket = () => {
2020
}
2121

2222
socket.on('disconnect', (reason, details) => {
23-
console.log('Client disconnected', reason, details);
23+
console.log('Client disconnected, reconnecting', reason, details);
2424

25-
if (!socket.active) {
26-
console.log('Inactive socket connection');
25+
setTimeout(() => {
2726
socket.connect();
28-
}
27+
}, 1000);
2928
});
3029

3130
socket.on('connect_error', (error) => {
32-
console.log('Connection error', error.message);
33-
if (!socket.active) {
34-
console.log('Inactive socket connection');
31+
console.log('Connection error, reconnecting', error.message);
32+
setTimeout(() => {
3533
socket.connect();
36-
}
34+
}, 1000);
3735
});
36+
37+
// dumbass brute force so nginx doesn't kill us
38+
setInterval(() => {
39+
socket.emit('ping');
40+
}, 5000);
3841
};
3942

4043
export const socketSubscribeTo = (emission, callback) => {

server/controllers/sockets.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ let student_room = crypto.randomBytes(72).toString('base64');
1414
*/
1515
exports.init = function (server) {
1616
sio = require("socket.io")(server, {
17+
pingTimeout: 45000,
18+
pingInterval: 2000,
19+
maxHttpBufferSize: 1e7,
1720
cors: {
1821
origin: config.PROTOCOL + "://" + config.DOMAIN + ":" + config.CLIENT_PORT,
1922
methods: ["GET", "POST"]

0 commit comments

Comments
 (0)