Comments (6)
-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 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.
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.
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.
@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.
I confirm this patch works like a charm 👍
from node-unix-dgram.
Related Issues (20)
- Failing to compile on Travis with Node 4.2.1 HOT 2
- does not work on node 4 or node 5 HOT 2
- getting a "make" error when building on CentOS 7 HOT 2
- Can't install in node 6 HOT 1
- Buffer limited to 2048 on Mac OS HOT 6
- - sorry -
- callback not used in case of congestion HOT 1
- Improve mismatched type handling. HOT 1
- Error | Failing build unix-dgram on solaris HOT 4
- Install failed using Node v10 HOT 2
- nodejs 12 support HOT 1
- Nan::NAN_METHOD_RETURN_TYPE HOT 1
- 2.0.3 causes hangs on Node < 12 HOT 2
- No buffer space available, write errror HOT 5
- Failing to build/install with Cannot open include file: 'unistd.h' on Windows HOT 4
- unix-dgram does not seem to work with Node v13? HOT 3
- Failing to build (ubuntu 20.04) HOT 1
- Is it possible to add Windows support? HOT 1
- Doesn't build on Node 20.9.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-unix-dgram.