Description
Describe the bug
recovery function : maxDisconnectionDuration is not work
To Reproduce
i use official way:
https://socket.io/docs/v4/connection-state-recovery
i write a sample code :
https://codesandbox.io/p/devbox/github/socketio/chat-example/tree/cjs/step6?file=%2Findex.js%3A9%2C3-9%2C26
set parameter:
maxDisconnectionDuration: 2 * 60 * 1000 (2 minute)
skipMiddlewares: true
Test Case:
when disconnect the network : (1)elapsed time 30 second and i send message ,continue to (2) elapsed time 150 second(2 minute 30 second) and i send message
Recovery the network in elapsed time 3 minute , it still can send ( elapsed time 150 second) over time -maxDisconnectionDuration message to another client.
My question:
why does it over maxDisconnectionDuration time , it still can send message and client be received message???
Please fill the following code example:
https://codesandbox.io/p/devbox/github/socketio/chat-example/tree/cjs/step6?file=%2Findex.js%3A9%2C3-9%2C26
(but i set parameter below:
connectionStateRecovery: {
// the backup duration of the sessions and the packets
maxDisconnectionDuration: 2 * 60 * 1000,
// whether to skip middlewares upon successful recovery
skipMiddlewares: true,
}
)
Socket.IO server version: 4.7.5
Server
const express = require('express');
const { createServer } = require('node:http');
const { join } = require('node:path');
const { Server } = require('socket.io');
const app = express();
const server = createServer(app);
const io = new Server(server, {
connectionStateRecovery: {}
});
app.get('/', (req, res) => {
res.sendFile(join(__dirname, 'index.html'));
});
io.on('connection', (socket) => {
socket.on('chat message', (msg) => {
io.emit('chat message', msg);
});
});
server.listen(3000, () => {
console.log('server running at http://localhost:3000');
});
Socket.IO client version: 4.7.5
Client
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
const form = document.getElementById('form');
const input = document.getElementById('input');
const messages = document.getElementById('messages');
form.addEventListener('submit', (e) => {
e.preventDefault();
if (input.value) {
socket.emit('chat message', input.value);
input.value = '';
}
});
socket.on('chat message', (msg) => {
const item = document.createElement('li');
item.textContent = msg;
messages.appendChild(item);
window.scrollTo(0, document.body.scrollHeight);
});
</script>
Expected behavior
when disconnect time is over 2 minute, i send the message .
the messge should not be received by another client.
Platform:
- Device: Ubuntu 16.04
Additional context
whatever maxDisconnectionDuration is 1 min, 2 min ,5 min ; all over-time message can be received by another client.