N
N
nepster-web2015-08-18 21:16:34
JavaScript
nepster-web, 2015-08-18 21:16:34

Why does the disconnect event fail in socket.io?

There is quite a common structure on node.js + socket.io:

io.on('connection', function (socket) {

    socket.on('add user', function (hash, interlocutor_id) {

    });

    socket.on('private message', function (from, msg) {

    });

    socket.on('disconnect', function () {

    });
});

So the point is in a small chat with your custom requests. Everything works like this:
A user comes in, we get his socket, we check if his user_id is in the array, if not, he creates a room and pushes him there. If it is in the array, update the socket for it.
So everything works well until the moment when I start storming the f5 server. To finish eating I throw a small dos attack by holding F5. At some point after 20 - 30 requests, the disconnect event simply stops working.
Just in this event, the rooms are cleaned. And it turns out that the rooms are constantly replenished with duplicates.
I found a similar question on stackoverflow, where it was advised to do this:
var socket = io.connect(':8080', {'sync disconnect on unload': true});

Actually the problem is not solved. The disconnect event falls off and falls off with ends on all subsequent requests, how to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2015-08-18
@Sanasol

At least you don’t have to do it the way you do: https://toster.ru/answer?answer_id=477715

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question