NodeJS errno 37 on socket.connect

I'm trying to connect to multiple hosts in succession, this is the code to resolve the ip address and socket.connect() to each domain name (line[1]). This works on it's own but returns an errno 37 error when run in quick succession with different hosts. The best information I have on the error is:

" code: 'EPROTO', description: 'protocol error' "

Code:

$.connect(port, line[1], function() {
  this.write(request);   
});

Error:

{ [Error: connect Unknown system errno 37]
  code: 'Unknown system errno 37',
  errno: 'Unknown system errno 37',
  syscall: 'connect' }

How can I resolve this / why is this happening?

Thanks in advance.

EDIT: removed manual dns lookup code and added error report

duplicate with NodeJS crash when calling socket.connect in quick succession?

Seems to me opening sockets in rapid succession is asking for trouble.

Try waiting in between opening the sockets and play with the amount of time needed to wait.