tj / axon

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

unix socket reconnect fails #168

Open datvong-wm opened 6 years ago

datvong-wm commented 6 years ago

On linux, call to connect socket.connect("unix:///home/mypath")

fails with

RangeError: "port" option should be >= 0 and < 65536: NaN
    at lookupAndConnect (net.js:970:13)
    at Socket.connect (net.js:945:5)
    at Socket.connect (net.js:904:37)
    at SubSocket.Socket.connect (/home/app/node_modules/axon/lib/sockets/sock.js:295:8)
    at Timeout._onTimeout (/home/app/node_modules/axon/lib/sockets/sock.js:280:12)

First time called, the port containing "unix:///home/mypath" is parsed so port="/home/mypath" https://github.com/tj/axon/blob/df2f5bb1637e39f1391dfd8f355db94f9b768e87/lib/sockets/sock.js#L251

    if (port.protocol == "unix:") {
      host = fn;
      fn = undefined;
      port = port.pathname;

On timeout and subsequent retry, port of "/home/mypath" will fail because protocol "unix://" has been stripped from port.

    setTimeout(function(){
      debug('%s attempting reconnect', self.type);
      self.emit('reconnect attempt');
      sock.destroy();
      self.connect(port, host);
datvong-wm commented 6 years ago

PR #150 is a fix for this issue.

METACEO commented 6 years ago

@datvong-wm nice!