{"action":"created","comment":{"url":"https://api.github.com/repos/indexzero/node-portfinder/pulls/comments/53688701","id":53688701,"diff_hunk":"@@ -76,40 +76,52 @@ exports.getPort = function (options, callback) {\n     options = {};\n   }\n \n-  options.host = options.host || '::1';\n-  var hosts = [options.host, '0.0.0.0', '127.0.0.1'];\n+  var hosts = ['::1', '127.0.0.1', '0.0.0.0'];\n+  if (options.host) {\n+    hosts.push(options.host);\n+  }\n \n   // remove duplicate host arg if already in hosts array\n-  for (var i = 1; i < hosts.length; i++) {\n-    if (options.host === hosts[i]) {\n-      hosts.shift();\n-      break;\n-    }\n-  }\n+  var uniqueHosts = hosts.filter(function(host, index) {\n+    return hosts.indexOf(host) == index;\n+  });\n \n-  // create array of eventual found ports for each host\n-  var testPortFunctions = [];\n-  for (var j = 0; j < hosts.length; j++) {\n-    (function() {\n-      var jj = j;\n-      var testPortFn = function(callback) {\n-        internals.testPort({ host: hosts[jj], port: options.port }, callback);\n-      };\n-\n-      testPortFunctions.push(testPortFn);\n-    }());\n+  function findCommonOpenPort(portToTest) {\n+    var ports = [];\n+    var error;\n+    async.everyLimit(uniqueHosts, 1, function(host, next) {\n+      internals.testPort({\"host\": host, \"port\": portToTest}, function(err, port) {\n+        if (err) {\n+          error = err;\n+          return next(false); \n+        } else {\n+          ports.push(port);\n+\t\t  next(port);\n+        }\n+      });\n+    }, function(result) {\n+      if (!result) {\n+        return callback(error);\n+      } \n+\n+      var uniquePorts = ports.filter(function(port, index) {\n+        return ports.indexOf(port) == index;\n+      });\n+      if (uniquePorts.length > 1) {\n+        // find highes port\n+        uniquePorts.sort(function(a, b) {\n+          return a - b;\n+        });\n+        // test all of the hosts against highest port\n+        findCommonOpenPort(uniquePorts.pop());\n+      } else {\n+        callback(null, ports[0]);\n+      }\n+      \n+    });\n   }\n \n-  async.series(testPortFunctions, function(err, ports) {\n-    if (err) { return callback(err); }\n-\n-    var port = ports.pop();\n-    for (var i = 0; i < ports.length; i++) {\n-      if (port !== ports[i]) { return exports.getPort({ host: options.hosts, port: ports[i] }, callback); }\n-    }\n-\n-    return callback(null, port);\n-  });\n+  findCommonOpenPort(options.port || exports.basePort);","path":"lib/portfinder.js","position":74,"original_position":78,"commit_id":"7c66c2b86283ef213b7be76b4afbe608a1fa8d83","original_commit_id":"6577b54b6c92e7ad5b625722ca64d2b8aa0be38b","user":{"login":"eriktrom","id":830120,"avatar_url":"https://avatars.githubusercontent.com/u/830120?v=3","gravatar_id":"","url":"https://api.github.com/users/eriktrom","html_url":"https://github.com/eriktrom","followers_url":"https://api.github.com/users/eriktrom/followers","following_url":"https://api.github.com/users/eriktrom/following{/other_user}","gists_url":"https://api.github.com/users/eriktrom/gists{/gist_id}","starred_url":"https://api.github.com/users/eriktrom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eriktrom/subscriptions","organizations_url":"https://api.github.com/users/eriktrom/orgs","repos_url":"https://api.github.com/users/eriktrom/repos","events_url":"https://api.github.com/users/eriktrom/events{/privacy}","received_events_url":"https://api.github.com/users/eriktrom/received_events","type":"User","site_admin":false},"body":"the internals.testPort function already starts at the port given, the exports.nextPort(i think is the name) simply adds +=1 from there, so we can remove this line (if you found differently, let me know, going off memory)","created_at":"2016-02-22T20:37:07Z","updated_at":"2016-02-22T20:37:07Z","html_url":"https://github.com/indexzero/node-portfinder/pull/25#discussion_r53688701","pull_request_url":"https://api.github.com/repos/indexzero/node-portfinder/pulls/25","_links":{"self":{"href":"https://api.github.com/repos/indexzero/node-portfinder/pulls/comments/53688701"},"html":{"href":"https://github.com/indexzero/node-portfinder/pull/25#discussion_r53688701"},"pull_request":{"href":"https://api.github.com/repos/indexzero/node-portfinder/pulls/25"}}},"pull_request":{"url":"https://api.github.com/repos/indexzero/node-portfinder/pulls/25","id":59087958,"html_url":"https://github.com/indexzero/node-portfinder/pull/25","diff_url":"https://github.com/indexzero/node-portfinder/pull/25.diff","patch_url":"https://github.com/indexzero/node-portfinder/pull/25.patch","issue_url":"https://api.github.com/repos/indexzero/node-portfinder/issues/25","number":25,"state":"open","locked":false,"title":"fixed infinite loop when bind across local interfaces is different","user":{"login":"winfinit","id":1187417,"avatar_url":"https://avatars.githubusercontent.com/u/1187417?v=3","gravatar_id":"","url":"https://api.github.com/users/winfinit","html_url":"https://github.com/winfinit","followers_url":"https://api.github.com/users/winfinit/followers","following_url":"https://api.github.com/users/winfinit/following{/other_user}","gists_url":"https://api.github.com/users/winfinit/gists{/gist_id}","starred_url":"https://api.github.com/users/winfinit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/winfinit/subscriptions","organizations_url":"https://api.github.com/users/winfinit/orgs","repos_url":"https://api.github.com/users/winfinit/repos","events_url":"https://api.github.com/users/winfinit/events{/privacy}","received_events_url":"https://api.github.com/users/winfinit/received_events","type":"User","site_admin":false},"body":"currently in getPort, hosts ::1, 127.0.0.1, and 0.0.0.0 are treated the same, and if any of them are not, application falls into infinite loop, because \"if\" condition was testing just last and current port, while we have three ports, and if they happen not to match, recursion is triggered, however that recursion will always test \"current\" and last port, which always would return not true.\r\n\r\nso with some extra console.log you would see this:\r\n\r\n```\r\nin testPortFn: ::1 undefined\r\nin testPortFn: 0.0.0.0 undefined\r\nin testPortFn: 127.0.0.1 undefined\r\nin getPorts: [ 3000, 3001, 3001 ]\r\nin testPortFn: ::1 3000\r\nin testPortFn: 0.0.0.0 3000\r\nin testPortFn: 127.0.0.1 3000\r\nin getPorts: [ 3000, 3001, 3001 ]\r\nin testPortFn: ::1 3000\r\nin testPortFn: 0.0.0.0 3000\r\nin testPortFn: 127.0.0.1 3000\r\nin getPorts: [ 3000, 3001, 3001 ]\r\n...\r\n```\r\n\r\ni've updated getPort function to test for unique items, and if more than one returned, it will sort that ports array, and trigger a new recursion against highest port\r\n\r\nthis issue would fix reported #24 issue.\r\n\r\n","created_at":"2016-02-11T20:22:18Z","updated_at":"2016-02-22T20:37:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ccb44ea534d693aca4b884f23b9e4d0452d742f9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/indexzero/node-portfinder/pulls/25/commits","review_comments_url":"https://api.github.com/repos/indexzero/node-portfinder/pulls/25/comments","review_comment_url":"https://api.github.com/repos/indexzero/node-portfinder/pulls/comments{/number}","comments_url":"https://api.github.com/repos/indexzero/node-portfinder/issues/25/comments","statuses_url":"https://api.github.com/repos/indexzero/node-portfinder/statuses/7c66c2b86283ef213b7be76b4afbe608a1fa8d83","head":{"label":"winfinit:master","ref":"master","sha":"7c66c2b86283ef213b7be76b4afbe608a1fa8d83","user":{"login":"winfinit","id":1187417,"avatar_url":"https://avatars.githubusercontent.com/u/1187417?v=3","gravatar_id":"","url":"https://api.github.com/users/winfinit","html_url":"https://github.com/winfinit","followers_url":"https://api.github.com/users/winfinit/followers","following_url":"https://api.github.com/users/winfinit/following{/other_user}","gists_url":"https://api.github.com/users/winfinit/gists{/gist_id}","starred_url":"https://api.github.com/users/winfinit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/winfinit/subscriptions","organizations_url":"https://api.github.com/users/winfinit/orgs","repos_url":"https://api.github.com/users/winfinit/repos","events_url":"https://api.github.com/users/winfinit/events{/privacy}","received_events_url":"https://api.github.com/users/winfinit/received_events","type":"User","site_admin":false},"repo":{"id":51536149,"name":"node-portfinder","full_name":"winfinit/node-portfinder","owner":{"login":"winfinit","id":1187417,"avatar_url":"https://avatars.githubusercontent.com/u/1187417?v=3","gravatar_id":"","url":"https://api.github.com/users/winfinit","html_url":"https://github.com/winfinit","followers_url":"https://api.github.com/users/winfinit/followers","following_url":"https://api.github.com/users/winfinit/following{/other_user}","gists_url":"https://api.github.com/users/winfinit/gists{/gist_id}","starred_url":"https://api.github.com/users/winfinit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/winfinit/subscriptions","organizations_url":"https://api.github.com/users/winfinit/orgs","repos_url":"https://api.github.com/users/winfinit/repos","events_url":"https://api.github.com/users/winfinit/events{/privacy}","received_events_url":"https://api.github.com/users/winfinit/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/winfinit/node-portfinder","description":"A simple tool to find an open port or domain socket on the current machine","fork":true,"url":"https://api.github.com/repos/winfinit/node-portfinder","forks_url":"https://api.github.com/repos/winfinit/node-portfinder/forks","keys_url":"https://api.github.com/repos/winfinit/node-portfinder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/winfinit/node-portfinder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/winfinit/node-portfinder/teams","hooks_url":"https://api.github.com/repos/winfinit/node-portfinder/hooks","issue_events_url":"https://api.github.com/repos/winfinit/node-portfinder/issues/events{/number}","events_url":"https://api.github.com/repos/winfinit/node-portfinder/events","assignees_url":"https://api.github.com/repos/winfinit/node-portfinder/assignees{/user}","branches_url":"https://api.github.com/repos/winfinit/node-portfinder/branches{/branch}","tags_url":"https://api.github.com/repos/winfinit/node-portfinder/tags","blobs_url":"https://api.github.com/repos/winfinit/node-portfinder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/winfinit/node-portfinder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/winfinit/node-portfinder/git/refs{/sha}","trees_url":"https://api.github.com/repos/winfinit/node-portfinder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/winfinit/node-portfinder/statuses/{sha}","languages_url":"https://api.github.com/repos/winfinit/node-portfinder/languages","stargazers_url":"https://api.github.com/repos/winfinit/node-portfinder/stargazers","contributors_url":"https://api.github.com/repos/winfinit/node-portfinder/contributors","subscribers_url":"https://api.github.com/repos/winfinit/node-portfinder/subscribers","subscription_url":"https://api.github.com/repos/winfinit/node-portfinder/subscription","commits_url":"https://api.github.com/repos/winfinit/node-portfinder/commits{/sha}","git_commits_url":"https://api.github.com/repos/winfinit/node-portfinder/git/commits{/sha}","comments_url":"https://api.github.com/repos/winfinit/node-portfinder/comments{/number}","issue_comment_url":"https://api.github.com/repos/winfinit/node-portfinder/issues/comments{/number}","contents_url":"https://api.github.com/repos/winfinit/node-portfinder/contents/{+path}","compare_url":"https://api.github.com/repos/winfinit/node-portfinder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/winfinit/node-portfinder/merges","archive_url":"https://api.github.com/repos/winfinit/node-portfinder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/winfinit/node-portfinder/downloads","issues_url":"https://api.github.com/repos/winfinit/node-portfinder/issues{/number}","pulls_url":"https://api.github.com/repos/winfinit/node-portfinder/pulls{/number}","milestones_url":"https://api.github.com/repos/winfinit/node-portfinder/milestones{/number}","notifications_url":"https://api.github.com/repos/winfinit/node-portfinder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/winfinit/node-portfinder/labels{/name}","releases_url":"https://api.github.com/repos/winfinit/node-portfinder/releases{/id}","deployments_url":"https://api.github.com/repos/winfinit/node-portfinder/deployments","created_at":"2016-02-11T18:23:29Z","updated_at":"2016-02-11T18:23:30Z","pushed_at":"2016-02-22T20:27:23Z","git_url":"git://github.com/winfinit/node-portfinder.git","ssh_url":"git@github.com:winfinit/node-portfinder.git","clone_url":"https://github.com/winfinit/node-portfinder.git","svn_url":"https://github.com/winfinit/node-portfinder","homepage":"http://github.com/indexzero/node-portfinder","size":30,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"indexzero:master","ref":"master","sha":"669ed062561cff1c522341977e9b9cdb1688d3cf","user":{"login":"indexzero","id":4624,"avatar_url":"https://avatars.githubusercontent.com/u/4624?v=3","gravatar_id":"","url":"https://api.github.com/users/indexzero","html_url":"https://github.com/indexzero","followers_url":"https://api.github.com/users/indexzero/followers","following_url":"https://api.github.com/users/indexzero/following{/other_user}","gists_url":"https://api.github.com/users/indexzero/gists{/gist_id}","starred_url":"https://api.github.com/users/indexzero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indexzero/subscriptions","organizations_url":"https://api.github.com/users/indexzero/orgs","repos_url":"https://api.github.com/users/indexzero/repos","events_url":"https://api.github.com/users/indexzero/events{/privacy}","received_events_url":"https://api.github.com/users/indexzero/received_events","type":"User","site_admin":false},"repo":{"id":2018652,"name":"node-portfinder","full_name":"indexzero/node-portfinder","owner":{"login":"indexzero","id":4624,"avatar_url":"https://avatars.githubusercontent.com/u/4624?v=3","gravatar_id":"","url":"https://api.github.com/users/indexzero","html_url":"https://github.com/indexzero","followers_url":"https://api.github.com/users/indexzero/followers","following_url":"https://api.github.com/users/indexzero/following{/other_user}","gists_url":"https://api.github.com/users/indexzero/gists{/gist_id}","starred_url":"https://api.github.com/users/indexzero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indexzero/subscriptions","organizations_url":"https://api.github.com/users/indexzero/orgs","repos_url":"https://api.github.com/users/indexzero/repos","events_url":"https://api.github.com/users/indexzero/events{/privacy}","received_events_url":"https://api.github.com/users/indexzero/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/indexzero/node-portfinder","description":"A simple tool to find an open port or domain socket on the current machine","fork":false,"url":"https://api.github.com/repos/indexzero/node-portfinder","forks_url":"https://api.github.com/repos/indexzero/node-portfinder/forks","keys_url":"https://api.github.com/repos/indexzero/node-portfinder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/indexzero/node-portfinder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/indexzero/node-portfinder/teams","hooks_url":"https://api.github.com/repos/indexzero/node-portfinder/hooks","issue_events_url":"https://api.github.com/repos/indexzero/node-portfinder/issues/events{/number}","events_url":"https://api.github.com/repos/indexzero/node-portfinder/events","assignees_url":"https://api.github.com/repos/indexzero/node-portfinder/assignees{/user}","branches_url":"https://api.github.com/repos/indexzero/node-portfinder/branches{/branch}","tags_url":"https://api.github.com/repos/indexzero/node-portfinder/tags","blobs_url":"https://api.github.com/repos/indexzero/node-portfinder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/indexzero/node-portfinder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/indexzero/node-portfinder/git/refs{/sha}","trees_url":"https://api.github.com/repos/indexzero/node-portfinder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/indexzero/node-portfinder/statuses/{sha}","languages_url":"https://api.github.com/repos/indexzero/node-portfinder/languages","stargazers_url":"https://api.github.com/repos/indexzero/node-portfinder/stargazers","contributors_url":"https://api.github.com/repos/indexzero/node-portfinder/contributors","subscribers_url":"https://api.github.com/repos/indexzero/node-portfinder/subscribers","subscription_url":"https://api.github.com/repos/indexzero/node-portfinder/subscription","commits_url":"https://api.github.com/repos/indexzero/node-portfinder/commits{/sha}","git_commits_url":"https://api.github.com/repos/indexzero/node-portfinder/git/commits{/sha}","comments_url":"https://api.github.com/repos/indexzero/node-portfinder/comments{/number}","issue_comment_url":"https://api.github.com/repos/indexzero/node-portfinder/issues/comments{/number}","contents_url":"https://api.github.com/repos/indexzero/node-portfinder/contents/{+path}","compare_url":"https://api.github.com/repos/indexzero/node-portfinder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/indexzero/node-portfinder/merges","archive_url":"https://api.github.com/repos/indexzero/node-portfinder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/indexzero/node-portfinder/downloads","issues_url":"https://api.github.com/repos/indexzero/node-portfinder/issues{/number}","pulls_url":"https://api.github.com/repos/indexzero/node-portfinder/pulls{/number}","milestones_url":"https://api.github.com/repos/indexzero/node-portfinder/milestones{/number}","notifications_url":"https://api.github.com/repos/indexzero/node-portfinder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/indexzero/node-portfinder/labels{/name}","releases_url":"https://api.github.com/repos/indexzero/node-portfinder/releases{/id}","deployments_url":"https://api.github.com/repos/indexzero/node-portfinder/deployments","created_at":"2011-07-08T16:15:01Z","updated_at":"2016-02-17T15:25:02Z","pushed_at":"2016-02-22T20:27:24Z","git_url":"git://github.com/indexzero/node-portfinder.git","ssh_url":"git@github.com:indexzero/node-portfinder.git","clone_url":"https://github.com/indexzero/node-portfinder.git","svn_url":"https://github.com/indexzero/node-portfinder","homepage":"http://github.com/indexzero/node-portfinder","size":33,"stargazers_count":129,"watchers_count":129,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":8,"forks":31,"open_issues":8,"watchers":129,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/indexzero/node-portfinder/pulls/25"},"html":{"href":"https://github.com/indexzero/node-portfinder/pull/25"},"issue":{"href":"https://api.github.com/repos/indexzero/node-portfinder/issues/25"},"comments":{"href":"https://api.github.com/repos/indexzero/node-portfinder/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/indexzero/node-portfinder/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/indexzero/node-portfinder/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/indexzero/node-portfinder/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/indexzero/node-portfinder/statuses/7c66c2b86283ef213b7be76b4afbe608a1fa8d83"}}}}