A function for checking local port availability #6

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
@jdpaton

jdpaton commented Nov 7, 2012

This local-only function has the additional check of establishing
a listening socket on the intended port to check availability, which
is destroyed as soon as it is in listening status.

This solved an issue I was having where a port established by SSH was being returned as 'open' by portscanner, i.e:

root     43716     1  0 Nov06 ?        00:00:00 ssh -L 0.0.0.0:35005:192.168.3.218:4101 -f stackato@localhost -N -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 

Add a findALocalPortNotInUse function
This local-only function has the additional check of establishing
a listening socket on the intended port to check availability, which
is destroyed as soon as it is in listening status.
+ server.listen(port);
+ server.on('error', function (e) {
+ if (e.code == 'EADDRINUSE') {
+ portscanner.findLocalPortNotInUse(port, endPort, callback);

This comment has been minimized.

@EndangeredMassa

EndangeredMassa Dec 24, 2013

Contributor

Shouldn't this be portscanner.findLocalPortNotInUse(port+1, endPort, callback); (port+1 instead of port)? It appears that if the first port that hits EADDRINUSE will cause an infinite loop here.

It also appears that this line references findLocalPortNotInUse instead of findALocalPortNotInUse.

@EndangeredMassa

EndangeredMassa Dec 24, 2013

Contributor

Shouldn't this be portscanner.findLocalPortNotInUse(port+1, endPort, callback); (port+1 instead of port)? It appears that if the first port that hits EADDRINUSE will cause an infinite loop here.

It also appears that this line references findLocalPortNotInUse instead of findALocalPortNotInUse.

@EndangeredMassa

This comment has been minimized.

Show comment
Hide comment
@EndangeredMassa

EndangeredMassa Jan 7, 2014

Contributor

I'm closing this old PR. I apologize for the delay in addressing it.

If this is still something you would like to pursue, please reopen.

Contributor

EndangeredMassa commented Jan 7, 2014

I'm closing this old PR. I apologize for the delay in addressing it.

If this is still something you would like to pursue, please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment