{"action":"created","comment":{"url":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/comments/236689591","pull_request_review_id":178814632,"id":236689591,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNjY4OTU5MQ==","diff_hunk":"@@ -418,7 +407,42 @@ function startDevServer(config, options) {\n \n       status(uri, options, log, argv.color);\n     });\n+  } else {\n+    // only run port finder if no port as been specified\n+    portRetries = 0;\n+    portfinder.basePort = DEFAULT_PORT;\n+    server.listeningApp.on('error', (err) => {\n+      if (err.code === 'EADDRINUSE' && portRetries < DEFAULT_PORT_RETRY) {\n+        tryStartListening(options, suffix, log);\n+        return;\n+      }\n+      throw err;\n+    });\n+    tryStartListening(options, suffix, log);\n   }\n }\n \n+function tryStartListening(options, suffix, log) {\n+  portRetries += 1;\n+  portfinder.getPort((err, port) => {","path":"bin/webpack-dev-server.js","position":67,"original_position":67,"commit_id":"e4112826a66ec50c6bdfd62030f1ef209a958ad5","original_commit_id":"e4112826a66ec50c6bdfd62030f1ef209a958ad5","user":{"login":"u9520107","id":2562164,"node_id":"MDQ6VXNlcjI1NjIxNjQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2562164?v=4","gravatar_id":"","url":"https://api.github.com/users/u9520107","html_url":"https://github.com/u9520107","followers_url":"https://api.github.com/users/u9520107/followers","following_url":"https://api.github.com/users/u9520107/following{/other_user}","gists_url":"https://api.github.com/users/u9520107/gists{/gist_id}","starred_url":"https://api.github.com/users/u9520107/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/u9520107/subscriptions","organizations_url":"https://api.github.com/users/u9520107/orgs","repos_url":"https://api.github.com/users/u9520107/repos","events_url":"https://api.github.com/users/u9520107/events{/privacy}","received_events_url":"https://api.github.com/users/u9520107/received_events","type":"User","site_admin":false},"body":"OK!","created_at":"2018-11-27T14:36:34Z","updated_at":"2018-11-27T14:36:34Z","html_url":"https://github.com/webpack/webpack-dev-server/pull/1577#discussion_r236689591","pull_request_url":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/1577","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/comments/236689591"},"html":{"href":"https://github.com/webpack/webpack-dev-server/pull/1577#discussion_r236689591"},"pull_request":{"href":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/1577"}},"in_reply_to_id":235878556},"pull_request":{"url":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/1577","id":232874014,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMyODc0MDE0","html_url":"https://github.com/webpack/webpack-dev-server/pull/1577","diff_url":"https://github.com/webpack/webpack-dev-server/pull/1577.diff","patch_url":"https://github.com/webpack/webpack-dev-server/pull/1577.patch","issue_url":"https://api.github.com/repos/webpack/webpack-dev-server/issues/1577","number":1577,"state":"open","locked":false,"title":"feat: Implement random port retry logic","user":{"login":"u9520107","id":2562164,"node_id":"MDQ6VXNlcjI1NjIxNjQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2562164?v=4","gravatar_id":"","url":"https://api.github.com/users/u9520107","html_url":"https://github.com/u9520107","followers_url":"https://api.github.com/users/u9520107/followers","following_url":"https://api.github.com/users/u9520107/following{/other_user}","gists_url":"https://api.github.com/users/u9520107/gists{/gist_id}","starred_url":"https://api.github.com/users/u9520107/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/u9520107/subscriptions","organizations_url":"https://api.github.com/users/u9520107/orgs","repos_url":"https://api.github.com/users/u9520107/repos","events_url":"https://api.github.com/users/u9520107/events{/privacy}","received_events_url":"https://api.github.com/users/u9520107/received_events","type":"User","site_admin":false},"body":"<!--\r\n  Thank you for submitting a pull request!\r\n\r\n  Please note that this template is not optional and all _ALL_ fields must be filled out, or your pull request may be rejected.\r\n\r\n  Please do not delete this template.\r\n  Please do remove this header to acknowledge this message.\r\n\r\n  Please place an x, no spaces, in all [ ] that apply\r\n-->\r\n\r\n- [ ] This is a **bugfix**\r\n- [x] This is a **feature**\r\n- [ ] This is a **code refactor**\r\n- [ ] This is a **test update**\r\n- [ ] This is a **docs update**\r\n- [ ] This is a **metadata update**\r\n\r\n### For Bugs and Features; did you add new tests?\r\nPort finding itself doesn't seem to have any test written already. If someone can suggest how to structure the test for this scenario, I can try and set something up.\r\n\r\n<!-- Please note that we won't approve your changes if you don't add tests. -->\r\n\r\n### Motivation / Use-Case\r\n\r\nTrying to support #1572.\r\nThe main change is to delay port finding to just before trying to run server.listen. Just this change alone reduced the time window between determining the available port and actually listening to it, as previously the compiler is initiated between this time frame. This naturally let most instances attempt to get available port in different moments and reducing the risk of trying to use the same port.\r\nAnother change is to listen to error event when port finding is used, when 'EADDRINUSE' error is encountered, retry the port finding again for up to 10 times. Not the most elegant solution, but should be sufficient for most prototyping scenarios.\r\nIf retried for 10 times and still cannot find available pot to use, the dev-server will error out like before.\r\n\r\n<!--\r\n  What existing problem does the pull request solve?\r\n\r\n  Please explain the motivation or use-case for making this change.\r\n  If this Pull Request addresses an issue, please link to the issue.\r\n-->\r\n\r\n### Breaking Changes\r\nUnless there are people relying on the fact that attempting to start multiple instances without specifying port could result in errors, this should not have breaking changes.\r\n<!--\r\n  If this PR introduces a breaking change, please describe the impact and a\r\n  potential migration path for existing applications.\r\n-->\r\n\r\n### Additional Info\r\nThis is my first contribution here, please comment if there are things that I should add.","created_at":"2018-11-22T06:42:35Z","updated_at":"2018-11-27T14:36:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"626f96f3624bcd2aaf54f34797234705135c11da","assignee":null,"assignees":[],"requested_reviewers":[{"login":"michael-ciniawsky","id":5419992,"node_id":"MDQ6VXNlcjU0MTk5OTI=","avatar_url":"https://avatars0.githubusercontent.com/u/5419992?v=4","gravatar_id":"","url":"https://api.github.com/users/michael-ciniawsky","html_url":"https://github.com/michael-ciniawsky","followers_url":"https://api.github.com/users/michael-ciniawsky/followers","following_url":"https://api.github.com/users/michael-ciniawsky/following{/other_user}","gists_url":"https://api.github.com/users/michael-ciniawsky/gists{/gist_id}","starred_url":"https://api.github.com/users/michael-ciniawsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michael-ciniawsky/subscriptions","organizations_url":"https://api.github.com/users/michael-ciniawsky/orgs","repos_url":"https://api.github.com/users/michael-ciniawsky/repos","events_url":"https://api.github.com/users/michael-ciniawsky/events{/privacy}","received_events_url":"https://api.github.com/users/michael-ciniawsky/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/1577/commits","review_comments_url":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/1577/comments","review_comment_url":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/webpack/webpack-dev-server/issues/1577/comments","statuses_url":"https://api.github.com/repos/webpack/webpack-dev-server/statuses/e4112826a66ec50c6bdfd62030f1ef209a958ad5","head":{"label":"u9520107:feature/retry-port","ref":"feature/retry-port","sha":"e4112826a66ec50c6bdfd62030f1ef209a958ad5","user":{"login":"u9520107","id":2562164,"node_id":"MDQ6VXNlcjI1NjIxNjQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2562164?v=4","gravatar_id":"","url":"https://api.github.com/users/u9520107","html_url":"https://github.com/u9520107","followers_url":"https://api.github.com/users/u9520107/followers","following_url":"https://api.github.com/users/u9520107/following{/other_user}","gists_url":"https://api.github.com/users/u9520107/gists{/gist_id}","starred_url":"https://api.github.com/users/u9520107/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/u9520107/subscriptions","organizations_url":"https://api.github.com/users/u9520107/orgs","repos_url":"https://api.github.com/users/u9520107/repos","events_url":"https://api.github.com/users/u9520107/events{/privacy}","received_events_url":"https://api.github.com/users/u9520107/received_events","type":"User","site_admin":false},"repo":{"id":157796011,"node_id":"MDEwOlJlcG9zaXRvcnkxNTc3OTYwMTE=","name":"webpack-dev-server","full_name":"u9520107/webpack-dev-server","private":false,"owner":{"login":"u9520107","id":2562164,"node_id":"MDQ6VXNlcjI1NjIxNjQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2562164?v=4","gravatar_id":"","url":"https://api.github.com/users/u9520107","html_url":"https://github.com/u9520107","followers_url":"https://api.github.com/users/u9520107/followers","following_url":"https://api.github.com/users/u9520107/following{/other_user}","gists_url":"https://api.github.com/users/u9520107/gists{/gist_id}","starred_url":"https://api.github.com/users/u9520107/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/u9520107/subscriptions","organizations_url":"https://api.github.com/users/u9520107/orgs","repos_url":"https://api.github.com/users/u9520107/repos","events_url":"https://api.github.com/users/u9520107/events{/privacy}","received_events_url":"https://api.github.com/users/u9520107/received_events","type":"User","site_admin":false},"html_url":"https://github.com/u9520107/webpack-dev-server","description":"Serves a webpack app. Updates the browser on changes.","fork":true,"url":"https://api.github.com/repos/u9520107/webpack-dev-server","forks_url":"https://api.github.com/repos/u9520107/webpack-dev-server/forks","keys_url":"https://api.github.com/repos/u9520107/webpack-dev-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/u9520107/webpack-dev-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/u9520107/webpack-dev-server/teams","hooks_url":"https://api.github.com/repos/u9520107/webpack-dev-server/hooks","issue_events_url":"https://api.github.com/repos/u9520107/webpack-dev-server/issues/events{/number}","events_url":"https://api.github.com/repos/u9520107/webpack-dev-server/events","assignees_url":"https://api.github.com/repos/u9520107/webpack-dev-server/assignees{/user}","branches_url":"https://api.github.com/repos/u9520107/webpack-dev-server/branches{/branch}","tags_url":"https://api.github.com/repos/u9520107/webpack-dev-server/tags","blobs_url":"https://api.github.com/repos/u9520107/webpack-dev-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/u9520107/webpack-dev-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/u9520107/webpack-dev-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/u9520107/webpack-dev-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/u9520107/webpack-dev-server/statuses/{sha}","languages_url":"https://api.github.com/repos/u9520107/webpack-dev-server/languages","stargazers_url":"https://api.github.com/repos/u9520107/webpack-dev-server/stargazers","contributors_url":"https://api.github.com/repos/u9520107/webpack-dev-server/contributors","subscribers_url":"https://api.github.com/repos/u9520107/webpack-dev-server/subscribers","subscription_url":"https://api.github.com/repos/u9520107/webpack-dev-server/subscription","commits_url":"https://api.github.com/repos/u9520107/webpack-dev-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/u9520107/webpack-dev-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/u9520107/webpack-dev-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/u9520107/webpack-dev-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/u9520107/webpack-dev-server/contents/{+path}","compare_url":"https://api.github.com/repos/u9520107/webpack-dev-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/u9520107/webpack-dev-server/merges","archive_url":"https://api.github.com/repos/u9520107/webpack-dev-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/u9520107/webpack-dev-server/downloads","issues_url":"https://api.github.com/repos/u9520107/webpack-dev-server/issues{/number}","pulls_url":"https://api.github.com/repos/u9520107/webpack-dev-server/pulls{/number}","milestones_url":"https://api.github.com/repos/u9520107/webpack-dev-server/milestones{/number}","notifications_url":"https://api.github.com/repos/u9520107/webpack-dev-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/u9520107/webpack-dev-server/labels{/name}","releases_url":"https://api.github.com/repos/u9520107/webpack-dev-server/releases{/id}","deployments_url":"https://api.github.com/repos/u9520107/webpack-dev-server/deployments","created_at":"2018-11-16T01:36:38Z","updated_at":"2018-11-16T01:36:40Z","pushed_at":"2018-11-22T06:15:17Z","git_url":"git://github.com/u9520107/webpack-dev-server.git","ssh_url":"git@github.com:u9520107/webpack-dev-server.git","clone_url":"https://github.com/u9520107/webpack-dev-server.git","svn_url":"https://github.com/u9520107/webpack-dev-server","homepage":null,"size":2151,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"webpack:master","ref":"master","sha":"55398b5de17b9a845b1ee5aaa90bb2002c25ddfb","user":{"login":"webpack","id":2105791,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMDU3OTE=","avatar_url":"https://avatars2.githubusercontent.com/u/2105791?v=4","gravatar_id":"","url":"https://api.github.com/users/webpack","html_url":"https://github.com/webpack","followers_url":"https://api.github.com/users/webpack/followers","following_url":"https://api.github.com/users/webpack/following{/other_user}","gists_url":"https://api.github.com/users/webpack/gists{/gist_id}","starred_url":"https://api.github.com/users/webpack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webpack/subscriptions","organizations_url":"https://api.github.com/users/webpack/orgs","repos_url":"https://api.github.com/users/webpack/repos","events_url":"https://api.github.com/users/webpack/events{/privacy}","received_events_url":"https://api.github.com/users/webpack/received_events","type":"Organization","site_admin":false},"repo":{"id":5839692,"node_id":"MDEwOlJlcG9zaXRvcnk1ODM5Njky","name":"webpack-dev-server","full_name":"webpack/webpack-dev-server","private":false,"owner":{"login":"webpack","id":2105791,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMDU3OTE=","avatar_url":"https://avatars2.githubusercontent.com/u/2105791?v=4","gravatar_id":"","url":"https://api.github.com/users/webpack","html_url":"https://github.com/webpack","followers_url":"https://api.github.com/users/webpack/followers","following_url":"https://api.github.com/users/webpack/following{/other_user}","gists_url":"https://api.github.com/users/webpack/gists{/gist_id}","starred_url":"https://api.github.com/users/webpack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webpack/subscriptions","organizations_url":"https://api.github.com/users/webpack/orgs","repos_url":"https://api.github.com/users/webpack/repos","events_url":"https://api.github.com/users/webpack/events{/privacy}","received_events_url":"https://api.github.com/users/webpack/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/webpack/webpack-dev-server","description":"Serves a webpack app. Updates the browser on changes.","fork":false,"url":"https://api.github.com/repos/webpack/webpack-dev-server","forks_url":"https://api.github.com/repos/webpack/webpack-dev-server/forks","keys_url":"https://api.github.com/repos/webpack/webpack-dev-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/webpack/webpack-dev-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/webpack/webpack-dev-server/teams","hooks_url":"https://api.github.com/repos/webpack/webpack-dev-server/hooks","issue_events_url":"https://api.github.com/repos/webpack/webpack-dev-server/issues/events{/number}","events_url":"https://api.github.com/repos/webpack/webpack-dev-server/events","assignees_url":"https://api.github.com/repos/webpack/webpack-dev-server/assignees{/user}","branches_url":"https://api.github.com/repos/webpack/webpack-dev-server/branches{/branch}","tags_url":"https://api.github.com/repos/webpack/webpack-dev-server/tags","blobs_url":"https://api.github.com/repos/webpack/webpack-dev-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/webpack/webpack-dev-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/webpack/webpack-dev-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/webpack/webpack-dev-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/webpack/webpack-dev-server/statuses/{sha}","languages_url":"https://api.github.com/repos/webpack/webpack-dev-server/languages","stargazers_url":"https://api.github.com/repos/webpack/webpack-dev-server/stargazers","contributors_url":"https://api.github.com/repos/webpack/webpack-dev-server/contributors","subscribers_url":"https://api.github.com/repos/webpack/webpack-dev-server/subscribers","subscription_url":"https://api.github.com/repos/webpack/webpack-dev-server/subscription","commits_url":"https://api.github.com/repos/webpack/webpack-dev-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/webpack/webpack-dev-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/webpack/webpack-dev-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/webpack/webpack-dev-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/webpack/webpack-dev-server/contents/{+path}","compare_url":"https://api.github.com/repos/webpack/webpack-dev-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/webpack/webpack-dev-server/merges","archive_url":"https://api.github.com/repos/webpack/webpack-dev-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/webpack/webpack-dev-server/downloads","issues_url":"https://api.github.com/repos/webpack/webpack-dev-server/issues{/number}","pulls_url":"https://api.github.com/repos/webpack/webpack-dev-server/pulls{/number}","milestones_url":"https://api.github.com/repos/webpack/webpack-dev-server/milestones{/number}","notifications_url":"https://api.github.com/repos/webpack/webpack-dev-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/webpack/webpack-dev-server/labels{/name}","releases_url":"https://api.github.com/repos/webpack/webpack-dev-server/releases{/id}","deployments_url":"https://api.github.com/repos/webpack/webpack-dev-server/deployments","created_at":"2012-09-17T10:52:18Z","updated_at":"2018-11-27T12:48:37Z","pushed_at":"2018-11-27T14:03:50Z","git_url":"git://github.com/webpack/webpack-dev-server.git","ssh_url":"git@github.com:webpack/webpack-dev-server.git","clone_url":"https://github.com/webpack/webpack-dev-server.git","svn_url":"https://github.com/webpack/webpack-dev-server","homepage":null,"size":2150,"stargazers_count":4644,"watchers_count":4644,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":800,"mirror_url":null,"archived":false,"open_issues_count":80,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":800,"open_issues":80,"watchers":4644,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/1577"},"html":{"href":"https://github.com/webpack/webpack-dev-server/pull/1577"},"issue":{"href":"https://api.github.com/repos/webpack/webpack-dev-server/issues/1577"},"comments":{"href":"https://api.github.com/repos/webpack/webpack-dev-server/issues/1577/comments"},"review_comments":{"href":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/1577/comments"},"review_comment":{"href":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/webpack/webpack-dev-server/pulls/1577/commits"},"statuses":{"href":"https://api.github.com/repos/webpack/webpack-dev-server/statuses/e4112826a66ec50c6bdfd62030f1ef209a958ad5"}},"author_association":"NONE"}}
{"actor":{"display_login":"u9520107"}}