Giter Club home page Giter Club logo

Comments (6)

bnoordhuis avatar bnoordhuis commented on August 18, 2024

-9 is EBADF, -11 is EAGAIN on Linux, -55 is ENOBUFS on OS X. I should probably add string error names but in the mean time consult errno.h on your system; the error code is the negated errno.

EBADF means you are trying to send on a socket you closed earlier. ENOBUFS means you've exhausted the kernel's resources and need to back off.

EAGAIN should have been handled by unix-dgram, I think. @santigimeno Why is it that send() starts the poll watcher but sendto() simply returns the error?

from node-unix-dgram.

santigimeno avatar santigimeno commented on August 18, 2024

@santigimeno Why is it that send() starts the poll watcher but sendto() simply returns the error?

@bnoordhuis IIRC send() just adds the UV_WRITABLE flag to the handle. The socket should already be watching for UV_READABLE events. bindings.send() should only be used for connected sockets and the UV_WRITABLE flag is needed for the congestion and writable events, see: https://github.com/bnoordhuis/node-unix-dgram#socketconnectremote_path.

EAGAIN should have been handled by unix-dgram

AFAICT, EAGAIN was never handled with non-connected sockets. In fact, that's one of the reasons I added the connected sockets functionality.

from node-unix-dgram.

santigimeno avatar santigimeno commented on August 18, 2024

For this issue I would use code similar to the one in https://github.com/bnoordhuis/node-unix-dgram#socketsendbuf-callback that allows implementing some congestion control.

from node-unix-dgram.

jbdemonte avatar jbdemonte commented on August 18, 2024

I tried the example code you just linked, but the writable / congestion events are never received on mac os

var unix = require('unix-dgram');
var client = unix.createSocket('unix_dgram');
var socketPath = __dirname + '/test.socket';

client.on('error', function (err) {
  console.error(err);
  client.close();
});

client.on('congestion', function() {
  console.log('congestion * * * * * * *');
  /* The server is not accepting data */
});

client.on('writable', function() {
  console.log('writable * * * * * * *');
  /* The server can accept data */
});

client.on('connect', function() {
  console.log('connected');
  for (var i = 0; i < 1000; i++) {
    var message = 'message ' + i;
    console.log('sending ' + message);
    client.send(Buffer.from(message));
  }
});

client.connect(socketPath);

Using this test code, here are the logs:

...
sending message 64
sending message 65
{ [Error: send -55] code: -55, errno: -55, syscall: 'send' }
sending message 66
{ [Error: send -9] code: -9, errno: -9, syscall: 'send' }
Assertion failed: (iter != watchers.end()), function StopWatcher, file ../src/unix_dgram.cc, line 166.
Abort trap: 6

On Debian, the events are well received and when having a congestion, the write pause and restart when socket is writable again

from node-unix-dgram.

santigimeno avatar santigimeno commented on August 18, 2024

@jbdemonte can you try the following patch?

diff --git a/src/unix_dgram.cc b/src/unix_dgram.cc
index 4c6e9e8..370b1e4 100644
--- a/src/unix_dgram.cc
+++ b/src/unix_dgram.cc
@@ -317,7 +317,7 @@ NAN_METHOD(Send) {
   err = 0;
   if (r == -1) {
     err = -errno;
-    if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
+    if ((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == ENOBUFS)) {
       watchers_t::iterator iter = watchers.find(fd);
       assert(iter != watchers.end());
       SocketContext* sc = iter->second;

from node-unix-dgram.

jbdemonte avatar jbdemonte commented on August 18, 2024

I confirm this patch works like a charm 👍

from node-unix-dgram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.