{"action":"created","comment":{"url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/comments/41926343","id":41926343,"diff_hunk":"@@ -125,9 +125,12 @@ class Server {\n   start() {\n     const hostname = this.hostname;\n     const port = this.port;\n-    this.httpServer = this.server.listen(port, function() {\n-      console.log('Server listening at http://%s:%s', hostname, port);\n-    });\n+    return new Promise(function (resolve) {\n+      this.httpServer = this.server.listen(port, function() {\n+        console.log('Server listening at http://%s:%s', hostname, port);\n+        this._readyPromise.then(resolve);","path":"lib/Server.js","position":10,"original_position":10,"commit_id":"3afbe2f2d57ade52f419764f22aff97865ca0bea","original_commit_id":"3afbe2f2d57ade52f419764f22aff97865ca0bea","user":{"login":"philikon","id":54918,"avatar_url":"https://avatars.githubusercontent.com/u/54918?v=3","gravatar_id":"","url":"https://api.github.com/users/philikon","html_url":"https://github.com/philikon","followers_url":"https://api.github.com/users/philikon/followers","following_url":"https://api.github.com/users/philikon/following{/other_user}","gists_url":"https://api.github.com/users/philikon/gists{/gist_id}","starred_url":"https://api.github.com/users/philikon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philikon/subscriptions","organizations_url":"https://api.github.com/users/philikon/orgs","repos_url":"https://api.github.com/users/philikon/repos","events_url":"https://api.github.com/users/philikon/events{/privacy}","received_events_url":"https://api.github.com/users/philikon/received_events","type":"User","site_admin":false},"body":"> [...] and instead we start everything here in `server.start()`. I think that would be more intuitive.\r\n\r\nYes! I agree.\r\n\r\n> I'll try to get that done tonight, then I'll pull in your changes :smile: \r\n\r\nOr perhaps the other way around, to avoid conflicts? Your call. :)","created_at":"2015-10-13T21:14:50Z","updated_at":"2015-10-13T21:14:50Z","html_url":"https://github.com/mjohnston/react-native-webpack-server/pull/104#discussion_r41926343","pull_request_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/104","_links":{"self":{"href":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/comments/41926343"},"html":{"href":"https://github.com/mjohnston/react-native-webpack-server/pull/104#discussion_r41926343"},"pull_request":{"href":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/104"}}},"pull_request":{"url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/104","id":47376273,"html_url":"https://github.com/mjohnston/react-native-webpack-server/pull/104","diff_url":"https://github.com/mjohnston/react-native-webpack-server/pull/104.diff","patch_url":"https://github.com/mjohnston/react-native-webpack-server/pull/104.patch","issue_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/104","number":104,"state":"open","locked":false,"title":"Fix a race condition in the `bundle` command","user":{"login":"philikon","id":54918,"avatar_url":"https://avatars.githubusercontent.com/u/54918?v=3","gravatar_id":"","url":"https://api.github.com/users/philikon","html_url":"https://github.com/philikon","followers_url":"https://api.github.com/users/philikon/followers","following_url":"https://api.github.com/users/philikon/following{/other_user}","gists_url":"https://api.github.com/users/philikon/gists{/gist_id}","starred_url":"https://api.github.com/users/philikon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philikon/subscriptions","organizations_url":"https://api.github.com/users/philikon/orgs","repos_url":"https://api.github.com/users/philikon/repos","events_url":"https://api.github.com/users/philikon/events{/privacy}","received_events_url":"https://api.github.com/users/philikon/received_events","type":"User","site_admin":false},"body":"These two changes fix a particular egregious race condition in the `rnws bundle` command on really performance-challenged machines, e.g. whatever steam-powered 19th century hardware Travis uses. The symptom would be `Error: socket hang up` in the part that attempts to `fetch` the bundle from the webpack server, which isn't ready yet. The only explanation that I have for this is that `fetch` is simply called too early sometimes. So the solution is to ensure it's only called when the server(s) is(are) definitely ready.\r\n\r\nIn this PR, we ensure that\r\n- the RN package server doesn't get started until the webpack compiler not only has written its entry file but the webpack server is actually listening\r\n- `fetch` won't be called until the RN package server is definitely up, which given the previous bullet point implies that the webpack server is listening\r\n\r\n(Disclaimer: I'm not entirely certain the first change is 100% necessary, but it helps us a lot in reasoning about when the webpack server has actually started up. It makes the promise chain simpler and I doubt that having it in place will have any impact on startup perf -- I haven't observed any, but I also haven't done any scientific measurements tbh.\r\n\r\nIf there *are* any concerns, we could alternatively have the RN package server continue to be launched after the entry file was written, and then make `Server.start()` return a `Promise.all` based on the RN package server and the webpack server. So long as we don't `fetch` before *both* servers are definitely listening on their ports... I chose not to go down that route because IMHO having `_startWebpackDevServer` resolve the promise when the server is actually listening made more sense to me.)\r\n\r\ncc @lightsofapollo ","created_at":"2015-10-11T21:47:50Z","updated_at":"2015-10-13T21:14:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"784741f1fc7e71c909954088fbd93a12cc3f203f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/104/commits","review_comments_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/104/comments","review_comment_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/104/comments","statuses_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/statuses/3afbe2f2d57ade52f419764f22aff97865ca0bea","head":{"label":"philikon:fix_more_races","ref":"fix_more_races","sha":"3afbe2f2d57ade52f419764f22aff97865ca0bea","user":{"login":"philikon","id":54918,"avatar_url":"https://avatars.githubusercontent.com/u/54918?v=3","gravatar_id":"","url":"https://api.github.com/users/philikon","html_url":"https://github.com/philikon","followers_url":"https://api.github.com/users/philikon/followers","following_url":"https://api.github.com/users/philikon/following{/other_user}","gists_url":"https://api.github.com/users/philikon/gists{/gist_id}","starred_url":"https://api.github.com/users/philikon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philikon/subscriptions","organizations_url":"https://api.github.com/users/philikon/orgs","repos_url":"https://api.github.com/users/philikon/repos","events_url":"https://api.github.com/users/philikon/events{/privacy}","received_events_url":"https://api.github.com/users/philikon/received_events","type":"User","site_admin":false},"repo":{"id":43527143,"name":"react-native-webpack-server","full_name":"philikon/react-native-webpack-server","owner":{"login":"philikon","id":54918,"avatar_url":"https://avatars.githubusercontent.com/u/54918?v=3","gravatar_id":"","url":"https://api.github.com/users/philikon","html_url":"https://github.com/philikon","followers_url":"https://api.github.com/users/philikon/followers","following_url":"https://api.github.com/users/philikon/following{/other_user}","gists_url":"https://api.github.com/users/philikon/gists{/gist_id}","starred_url":"https://api.github.com/users/philikon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philikon/subscriptions","organizations_url":"https://api.github.com/users/philikon/orgs","repos_url":"https://api.github.com/users/philikon/repos","events_url":"https://api.github.com/users/philikon/events{/privacy}","received_events_url":"https://api.github.com/users/philikon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/philikon/react-native-webpack-server","description":"Build React Native apps with Webpack","fork":true,"url":"https://api.github.com/repos/philikon/react-native-webpack-server","forks_url":"https://api.github.com/repos/philikon/react-native-webpack-server/forks","keys_url":"https://api.github.com/repos/philikon/react-native-webpack-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/philikon/react-native-webpack-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/philikon/react-native-webpack-server/teams","hooks_url":"https://api.github.com/repos/philikon/react-native-webpack-server/hooks","issue_events_url":"https://api.github.com/repos/philikon/react-native-webpack-server/issues/events{/number}","events_url":"https://api.github.com/repos/philikon/react-native-webpack-server/events","assignees_url":"https://api.github.com/repos/philikon/react-native-webpack-server/assignees{/user}","branches_url":"https://api.github.com/repos/philikon/react-native-webpack-server/branches{/branch}","tags_url":"https://api.github.com/repos/philikon/react-native-webpack-server/tags","blobs_url":"https://api.github.com/repos/philikon/react-native-webpack-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/philikon/react-native-webpack-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/philikon/react-native-webpack-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/philikon/react-native-webpack-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/philikon/react-native-webpack-server/statuses/{sha}","languages_url":"https://api.github.com/repos/philikon/react-native-webpack-server/languages","stargazers_url":"https://api.github.com/repos/philikon/react-native-webpack-server/stargazers","contributors_url":"https://api.github.com/repos/philikon/react-native-webpack-server/contributors","subscribers_url":"https://api.github.com/repos/philikon/react-native-webpack-server/subscribers","subscription_url":"https://api.github.com/repos/philikon/react-native-webpack-server/subscription","commits_url":"https://api.github.com/repos/philikon/react-native-webpack-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/philikon/react-native-webpack-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/philikon/react-native-webpack-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/philikon/react-native-webpack-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/philikon/react-native-webpack-server/contents/{+path}","compare_url":"https://api.github.com/repos/philikon/react-native-webpack-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/philikon/react-native-webpack-server/merges","archive_url":"https://api.github.com/repos/philikon/react-native-webpack-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/philikon/react-native-webpack-server/downloads","issues_url":"https://api.github.com/repos/philikon/react-native-webpack-server/issues{/number}","pulls_url":"https://api.github.com/repos/philikon/react-native-webpack-server/pulls{/number}","milestones_url":"https://api.github.com/repos/philikon/react-native-webpack-server/milestones{/number}","notifications_url":"https://api.github.com/repos/philikon/react-native-webpack-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/philikon/react-native-webpack-server/labels{/name}","releases_url":"https://api.github.com/repos/philikon/react-native-webpack-server/releases{/id}","created_at":"2015-10-01T23:46:22Z","updated_at":"2015-10-01T23:46:23Z","pushed_at":"2015-10-10T00:12:51Z","git_url":"git://github.com/philikon/react-native-webpack-server.git","ssh_url":"git@github.com:philikon/react-native-webpack-server.git","clone_url":"https://github.com/philikon/react-native-webpack-server.git","svn_url":"https://github.com/philikon/react-native-webpack-server","homepage":null,"size":793,"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":"mjohnston:master","ref":"master","sha":"42a2d29cf7a6a98318fe5dfd4a537be8c623a811","user":{"login":"mjohnston","id":331053,"avatar_url":"https://avatars.githubusercontent.com/u/331053?v=3","gravatar_id":"","url":"https://api.github.com/users/mjohnston","html_url":"https://github.com/mjohnston","followers_url":"https://api.github.com/users/mjohnston/followers","following_url":"https://api.github.com/users/mjohnston/following{/other_user}","gists_url":"https://api.github.com/users/mjohnston/gists{/gist_id}","starred_url":"https://api.github.com/users/mjohnston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjohnston/subscriptions","organizations_url":"https://api.github.com/users/mjohnston/orgs","repos_url":"https://api.github.com/users/mjohnston/repos","events_url":"https://api.github.com/users/mjohnston/events{/privacy}","received_events_url":"https://api.github.com/users/mjohnston/received_events","type":"User","site_admin":false},"repo":{"id":34033128,"name":"react-native-webpack-server","full_name":"mjohnston/react-native-webpack-server","owner":{"login":"mjohnston","id":331053,"avatar_url":"https://avatars.githubusercontent.com/u/331053?v=3","gravatar_id":"","url":"https://api.github.com/users/mjohnston","html_url":"https://github.com/mjohnston","followers_url":"https://api.github.com/users/mjohnston/followers","following_url":"https://api.github.com/users/mjohnston/following{/other_user}","gists_url":"https://api.github.com/users/mjohnston/gists{/gist_id}","starred_url":"https://api.github.com/users/mjohnston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjohnston/subscriptions","organizations_url":"https://api.github.com/users/mjohnston/orgs","repos_url":"https://api.github.com/users/mjohnston/repos","events_url":"https://api.github.com/users/mjohnston/events{/privacy}","received_events_url":"https://api.github.com/users/mjohnston/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mjohnston/react-native-webpack-server","description":"Build React Native apps with Webpack","fork":false,"url":"https://api.github.com/repos/mjohnston/react-native-webpack-server","forks_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/forks","keys_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/teams","hooks_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/hooks","issue_events_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/events{/number}","events_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/events","assignees_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/assignees{/user}","branches_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/branches{/branch}","tags_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/tags","blobs_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/statuses/{sha}","languages_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/languages","stargazers_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/stargazers","contributors_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/contributors","subscribers_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/subscribers","subscription_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/subscription","commits_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/contents/{+path}","compare_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/merges","archive_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/downloads","issues_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues{/number}","pulls_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls{/number}","milestones_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/milestones{/number}","notifications_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/labels{/name}","releases_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/releases{/id}","created_at":"2015-04-16T03:51:37Z","updated_at":"2015-10-13T21:12:57Z","pushed_at":"2015-10-11T21:47:50Z","git_url":"git://github.com/mjohnston/react-native-webpack-server.git","ssh_url":"git@github.com:mjohnston/react-native-webpack-server.git","clone_url":"https://github.com/mjohnston/react-native-webpack-server.git","svn_url":"https://github.com/mjohnston/react-native-webpack-server","homepage":null,"size":607,"stargazers_count":421,"watchers_count":421,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":40,"mirror_url":null,"open_issues_count":11,"forks":40,"open_issues":11,"watchers":421,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/104"},"html":{"href":"https://github.com/mjohnston/react-native-webpack-server/pull/104"},"issue":{"href":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/104"},"comments":{"href":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/104/comments"},"review_comments":{"href":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/104/comments"},"review_comment":{"href":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/104/commits"},"statuses":{"href":"https://api.github.com/repos/mjohnston/react-native-webpack-server/statuses/3afbe2f2d57ade52f419764f22aff97865ca0bea"}}}}