tj / axon

message-oriented socket library for node.js heavily inspired by zeromq
MIT License
1.5k stars 155 forks source link

Fix sock.js when reconnectin over a unix:///path #148

Closed navaru closed 9 years ago

navaru commented 9 years ago
var axon = require('axon')
var client = axon.socket('req')
var address = 'unix:///tmp/some.path'

client.connect(address)

Because the port is parsed in sock.connect(port, host) and the unix:// part of the string is removed, on reconnection passing the same variable port to the same function again will throw an error in node's net.js:

net.js:921
      throw new RangeError('port should be >= 0 and < 65536: ' + port);
            ^
RangeError: port should be >= 0 and < 65536: NaN
    at lookupAndConnect (net.js:921:13)
    at Socket.connect (net.js:898:5)
    at Socket.connect (net.js:860:37)
    at ReqSocket.Socket.connect (/Users/eugen/code/projects/evea/node_modules/axon/lib/sockets/sock.js:294:8)
    at null._onTimeout (/Users/eugen/code/projects/evea/node_modules/axon/lib/sockets/sock.js:279:12)
    at Timer.listOnTimeout (timers.js:89:15)
jcrugzz commented 9 years ago

@TEugen while it may seemingly fix the issue, this is not a solution to this problem. self.connect still needs to be called in order to re-setup the proper listeners and create a NEW socket. In this function we could potentially keep a reference around of the unix path in order to pass the correct thing back into self.connect. See if you can implement it with that strategy and I'll review