{"action":"opened","issue":{"url":"https://api.github.com/repos/nickdesaulniers/node-nanomsg/issues/200","repository_url":"https://api.github.com/repos/nickdesaulniers/node-nanomsg","labels_url":"https://api.github.com/repos/nickdesaulniers/node-nanomsg/issues/200/labels{/name}","comments_url":"https://api.github.com/repos/nickdesaulniers/node-nanomsg/issues/200/comments","events_url":"https://api.github.com/repos/nickdesaulniers/node-nanomsg/issues/200/events","html_url":"https://github.com/nickdesaulniers/node-nanomsg/issues/200","id":368288113,"node_id":"MDU6SXNzdWUzNjgyODgxMTM=","number":200,"title":"duplicate receive messages arriving?","user":{"login":"DrYSG","id":2865368,"node_id":"MDQ6VXNlcjI4NjUzNjg=","avatar_url":"https://avatars1.githubusercontent.com/u/2865368?v=4","gravatar_id":"","url":"https://api.github.com/users/DrYSG","html_url":"https://github.com/DrYSG","followers_url":"https://api.github.com/users/DrYSG/followers","following_url":"https://api.github.com/users/DrYSG/following{/other_user}","gists_url":"https://api.github.com/users/DrYSG/gists{/gist_id}","starred_url":"https://api.github.com/users/DrYSG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DrYSG/subscriptions","organizations_url":"https://api.github.com/users/DrYSG/orgs","repos_url":"https://api.github.com/users/DrYSG/repos","events_url":"https://api.github.com/users/DrYSG/events{/privacy}","received_events_url":"https://api.github.com/users/DrYSG/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-09T16:11:04Z","updated_at":"2018-10-09T16:11:04Z","closed_at":null,"author_association":"NONE","body":"This is very odd. I have a C++ program using  nng Nanomsg (wire protocol is identical to nanomsg). \r\nhttps://github.com/nanomsg/nng\r\n\r\nI have a simple test harness (client.exe and server.exe) using the CPP interface and I only see one copy of a message (sent in over bus protocol). However with this JS package I am getting two copies of each message sent (cpp -> JS node program).\r\n\r\nNode Version: 10.9.0\r\nnanomsg: 4.0.2\r\n\r\nThis means that I get two calls to the receive() callback for each packet that arrives.\r\n\r\nHere is my nanomsg receiver\r\n\r\n```\r\n\r\nconst nano = require('nanomsg')\r\nconst { Topics } = require('./Payloads/Packet')\r\n\r\nclass LMB {\r\n    constructor(config) {\r\n        this.sock\r\n        this.config = config\r\n        this.nodeName = config.nodeName\r\n        this.topicList = config.topicList\r\n        this.topics = Topics\r\n    }\r\n\r\n    connect() {\r\n        this.sock = nano.socket('bus')\r\n        this.sock.bind(this.config.urlList[0])\r\n        this.sock.connect(this.config.urlList[1])\r\n        this.sock.on('data', this.receive.bind(this))\r\n    }\r\n\r\n    send(topic, payload) {\r\n        let size = payload.length\r\n        let packet = new ArrayBuffer(size + 8)\r\n        let buffer = new Uint8Array(packet)\r\n        let view = new DataView(packet)\r\n        view.setUint32(0, topic, true)\r\n        view.setUint32(4, size, true)\r\n        buffer.set(payload, 8)\r\n        this.sock.send(buffer)\r\n    }\r\n\r\n    receive(packet) {\r\n        let view = new DataView(packet.buffer)\r\n        let topic = view.getUint32(0, true)\r\n        let size = view.getUint32(4, true)\r\n        let payload = packet.slice(8, packet.length - 1)\r\n        global.Dispatcher.process(topic, size, payload)\r\n    }\r\n}\r\n\r\nmodule.exports = { LMB }\r\n```\r\n\r\n\r\nand here is the config that it uses, and the two copies of the start message that appear. I confirmed with the VSCODE debugger via breakpoints and the receive() method is being called twice for each arrival of a packet over the network.\r\n\r\n```\r\nC:\\Program Files\\nodejs\\node.exe --inspect-brk=48723 orch.js \r\nDebugger listening on ws://127.0.0.1:48723/a3bc5322-9c99-4c22-b1fb-f053bb8d144f\r\n\r\nFor help, see: https://nodejs.org/en/docs/inspector\r\n\r\nOrcestrator config: \r\n{\r\n    \"nodeName\": \"YSG4206-Orchestrator\",\r\n    \"urlList\": [\r\n        \"tcp://127.0.0.1:2019\",\r\n        \"tcp://127.0.0.1:2018\"\r\n    ],\r\n    \"topicList\": [\r\n        \"sim.Actor.State.Test\"\r\n    ]\r\n}\r\nWaiting for messages..\r\n{\r\n    \"topic\": 6,\r\n    \"size\": 144,\r\n    \"topicString\": \"scenario.Ready\",\r\n    \"source\": \"AFSIM-YSG-Server\",\r\n    \"systemTime\": {\r\n        \"low\": -433850073,\r\n        \"high\": 30695395\r\n    },\r\n    \"systemTimeString\": \"Tue Oct  9 11:22:32 2018\",\r\n    \"description\": \"AFSIM Ready\"\r\n}\r\n******* starting ******\r\n{\r\n    \"topic\": 6,\r\n    \"size\": 144,\r\n    \"topicString\": \"scenario.Ready\",\r\n    \"source\": \"AFSIM-YSG-Server\",\r\n    \"systemTime\": {\r\n        \"low\": -433850073,\r\n        \"high\": 30695395\r\n    },\r\n    \"systemTimeString\": \"Tue Oct  9 11:22:32 2018\",\r\n    \"description\": \"AFSIM Ready\"\r\n}\r\n******* starting ******\r\n\r\n```\r\n"}}
{"actor":{"display_login":"DrYSG"}}