Comments (10)
indeed, if I run the test case:
var nano = require('./lib/index.js');
var argv = process.argv;
var bus = nano.socket('bus');
var addr = 'ipc:///tmp/' + argv[2];
var p1 = 'ipc:///tmp/' + argv[3];
console.log('binding to', addr);
bus.bind(addr);
console.log('connecting to', p1);
bus.connect(p1);
bus.on('message', function (buf) {
console.log('received message');
console.log(buf.toString());
});
var seq = 0;
setInterval(function () {
seq++;
console.log('sending...', seq);
bus.send(argv[2] + " " + seq);
}, 5000);
node test.js n0 n1
and node test.js n1 n0
I do receive the message twice! We will have to figure out if we're sending twice, or firing onmessage twice.
from node-nanomsg.
Looks more like a double receive than double send. Still digging.
from node-nanomsg.
We only set the callback to lib uv once, but it seems to be firing twice, with the same callback.
node-nanomsg/src/node_nanomsg.cc
Line 380 in 7538bfe
I wonder if there's some low level incompatibility with nanomsg bus sockets and lib uv?
I get the feeling that whatever libuv does to get notifications, might be getting notified twice for nanomsg bus sockets which would be a bug in nanomsg (or libuv). Writing a test case now.
from node-nanomsg.
I think this is an extension of #10 and #11. With bus, you should only have one process bind, and the rest connect, and they can still send each other messages. When each process binds and connects, then this problem arises. We can't differentiate the socket being marked readable twice from this vs receiving two different messages. A bus socket can send and receive by simply calling bind or receive. You don't relink them twice. For instance, socketA and socketB only share one bind/connect on an address; what you're doing is creating two bind/connect pairs, which is messing everything up (and by #10 and #11 we don't error out at the calls to bind).
For example:
var nano = require('../');
var bus1 = nano.socket('bus');
var bus2 = nano.socket('bus');
var addr1 = 'tcp://127.0.0.1:3000'
var addr2 = 'tcp://127.0.0.1:4000'
// Try commenting these in and rerunning for some fun!
//bus1.bind(addr1);
bus2.bind(addr2);
bus1.connect(addr2);
//bus2.connect(addr1);
bus1.on('message', function (buf) {
console.log('received message');
bus1.send('hello');
});
bus2.on('message', function (buf) {
console.log('hey, I can receive without binding');
});
bus2.send('o hai');
from node-nanomsg.
So in a sense, we're working correctly; we call our onmessage callback twice, since a call to send on a BUS socket that is both bound and connected to another BUS socket is technically notifying the receiver on two addresses. For a BUS socket, the binder and the connector are irrelevant, and each pair should ever be bound/connected via one address, otherwise you can expect onmessage to be invoked once for each address they share.
from node-nanomsg.
Hello Nick! For the first i want to say thank you for your library! However, i have a two issues to talk about, the first its according to this conversation, i'm sure that implementation of "bus" pattern is not correct, and its shouldn't fired up same event twice in that and any other case, because its one of "original" tasks for message queue service. (http://tim.dysinger.net/posts/2013-09-16-getting-started-with-nanomsg.html - last case show how it should be works). I want to help fix that, but its bring us to next issue. You library have a C++ abstraction binding inside and js interface have binding to it - what the reason for this method? May be it can be easy with binding to original (on pure C) library?
from node-nanomsg.
#38 (comment) - at this example missed sockets topology
from node-nanomsg.
i'm sure that implementation of "bus" pattern is not correct
bus is implemented correctly. scroll to the bottom of the getting started link you reference to see dups
a C++ abstraction binding inside and js interface have binding to it - what the reason for this method? May be it can be easy with binding to original (on pure C) library?
we do native abstraction this way to switch data back and forth between V8 JavaScript and C.
from node-nanomsg.
I want to help fix that
Cool, if you spot something wrong, we're always happy to review patches.
what the reason for this method?
v8 does not expose a C API. nanomsg and v8 can only be tied together through C++ (or maybe now Rust) since v8's functions which we NEED for converting JS types to C types have C++ linkage and a C++ ABI.
from node-nanomsg.
yea it'd be nice if we didnt have to use C++.
You know... in addition to Rust, we could've also used https://github.com/node-ffi/node-ffi, but early on when i just started running some experiments and tests on a similar binding for iojs and trying find the best way to write this, I ran a series of performance tests with node-ffi and found that each call carried a higher overhead than calls made with NAN... so that's i went with NAN at the time. Also that was about a year ago so maybe things are different now.
from node-nanomsg.
Related Issues (20)
- add support for nng HOT 4
- Error handling HOT 3
- TypeError: Path must be a string. Received undefined HOT 2
- rfc links
- Compile error in Node V12.* HOT 6
- vulnerable dependencies HOT 1
- deprecation warning from Nan::Callback::call HOT 2
- DeprecationWarning: Buffer HOT 2
- remove package-lock.json from .gitignore HOT 2
- fallthrough warnings in nanomsg HOT 1
- are we handling scopes correctly? HOT 1
- How do i catch timeout on reqrep?
- Carsh When msg send 10K per second HOT 2
- Electron compatibility: "Loading non-context-aware native module in renderer" HOT 1
- node 14.15 compatability HOT 1
- (node:660) electron: The default of contextIsolation is deprecated and will be c hanging from false to true in a future release of Electron. HOT 2
- Double handle scope
- -Wcast-function-type in nodejs/src/node.h
- sub: filter by binary chan prefix? HOT 1
- npm install --use_system_libnanomsg=true fails
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-nanomsg.