{"action":"created","issue":{"url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/104","labels_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/104/labels{/name}","comments_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/104/comments","events_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/104/events","html_url":"https://github.com/mjohnston/react-native-webpack-server/pull/104","id":110884696,"number":104,"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},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-11T21:47:50Z","updated_at":"2015-10-14T01:46:29Z","closed_at":"2015-10-13T23:39:21Z","pull_request":{"url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/pulls/104","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"},"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 "},"comment":{"url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/comments/147901037","html_url":"https://github.com/mjohnston/react-native-webpack-server/pull/104#issuecomment-147901037","issue_url":"https://api.github.com/repos/mjohnston/react-native-webpack-server/issues/104","id":147901037,"user":{"login":"elliottsj","id":2177366,"avatar_url":"https://avatars.githubusercontent.com/u/2177366?v=3","gravatar_id":"","url":"https://api.github.com/users/elliottsj","html_url":"https://github.com/elliottsj","followers_url":"https://api.github.com/users/elliottsj/followers","following_url":"https://api.github.com/users/elliottsj/following{/other_user}","gists_url":"https://api.github.com/users/elliottsj/gists{/gist_id}","starred_url":"https://api.github.com/users/elliottsj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elliottsj/subscriptions","organizations_url":"https://api.github.com/users/elliottsj/orgs","repos_url":"https://api.github.com/users/elliottsj/repos","events_url":"https://api.github.com/users/elliottsj/events{/privacy}","received_events_url":"https://api.github.com/users/elliottsj/received_events","type":"User","site_admin":false},"created_at":"2015-10-14T01:46:29Z","updated_at":"2015-10-14T01:46:29Z","body":":+1: released as 0.7.2"}}