Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recovery ability (parameter : maxDisconnectionDuration: 2 * 60 * 1000) Over 2 minute ,it still can send message to another client??? #5166

Open
skyfall1970 opened this issue Aug 12, 2024 · 1 comment
Labels
question Further information is requested

Comments

@skyfall1970
Copy link

skyfall1970 commented Aug 12, 2024

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.

@skyfall1970 skyfall1970 added the to triage Waiting to be triaged by a member of the team label Aug 12, 2024
@darrachequesne
Copy link
Member

Hi!

On the client side, the messages are buffered during disconnection, and will be sent upon reconnection.

On the server side, if connection state recovery is enabled, the messages are buffered while the client is disconnected, up to the maxDisconnectionDuration value.

Reference: https://socket.io/docs/v4/connection-state-recovery

@darrachequesne darrachequesne added question Further information is requested and removed to triage Waiting to be triaged by a member of the team labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants