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

Support 'drain' event and boolean response in socket.emit() in order to implement proper Node.js style backpressuring #3158

Open
1 of 2 tasks
illarion opened this issue Jan 13, 2018 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@illarion
Copy link

You want to:

  • report a bug
  • request a feature

Current behaviour

From the documentation and code of socket.io and its dependencies such as engine.io and ws it's not clear, how to implement output intensive server application, that is capable to handle slow clients by considering "backpressure" (As described in https://nodejs.org/en/docs/guides/backpressuring-in-streams/ ). And it seems to be impossible.

Steps to reproduce (if the current behaviour is a bug)

It's not a bug, so, no step to reproduce.

Expected behaviour

I would expect socket.emit() to return bool and socket have 'drain' event, so that I could work with it like this (simplified):

someExternalSourceOfEvents.on('frequent_event', function(data) {
   var ok = socket.emit('event', data);
   if (!ok) {
       someExternalSourceOfEvents.pause();
       socket.on('drain', function() {
           someExternalSourceOfEvents.continue();
       });
   }
});
@illarion
Copy link
Author

illarion commented Dec 3, 2018

Any updates?

@darrachequesne darrachequesne added the enhancement New feature or request label Feb 23, 2021
@darrachequesne
Copy link
Member

For what it's worth, you can listen to the drain event emitted by the underlying engine:

socket.emit("some event");

// server side
socket.conn.on("drain", () => {
  // ...
});

// client side
socket.io.engine.on("drain", () => {
  // ...
});

Reference: https://socket.io/docs/v4/server-api/#socketconn

socket.emit() always return true though. Not sure if that covers the initial use case.

@darrachequesne darrachequesne added documentation Improvements or additions to documentation and removed enhancement New feature or request labels Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants