{"action":"closed","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/10017","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10017/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10017/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10017/events","html_url":"https://github.com/elastic/elasticsearch/issues/10017","id":60103927,"number":10017,"title":"Race condition in lifecycles of DiscoveryService and Discovery","user":{"login":"brwe","id":4320215,"avatar_url":"https://avatars.githubusercontent.com/u/4320215?v=3","gravatar_id":"","url":"https://api.github.com/users/brwe","html_url":"https://github.com/brwe","followers_url":"https://api.github.com/users/brwe/followers","following_url":"https://api.github.com/users/brwe/following{/other_user}","gists_url":"https://api.github.com/users/brwe/gists{/gist_id}","starred_url":"https://api.github.com/users/brwe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brwe/subscriptions","organizations_url":"https://api.github.com/users/brwe/orgs","repos_url":"https://api.github.com/users/brwe/repos","events_url":"https://api.github.com/users/brwe/events{/privacy}","received_events_url":"https://api.github.com/users/brwe/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Discovery","name":":Discovery","color":"009800"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/adoptme","name":"adoptme","color":"207de5"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/bug","name":"bug","color":"9e2c2c"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/discuss","name":"discuss","color":"fbca04"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2015-03-06T13:51:34Z","updated_at":"2016-10-25T16:10:56Z","closed_at":"2016-10-25T16:10:56Z","body":"A fresh master does (rarely) not send the first cluster state due to a race condition in lifecycles of `DiscoveryService` and its member `Discovery`. In `DiscoveryService.doStart()` the `Discovery` is started but the lifecycle for `DiscoveryService` is started only after that. This is why when the first cluster state reaches `DiscoveryService.publish` the lifecycle might or might not have started.\r\n\r\nI am not yet sure what the implications are. However, when I add an artificial delay in `DiscoveryService.doStart()` like this:\r\n\r\n```\r\n@Override\r\n    protected void doStart() throws ElasticsearchException {\r\n        initialStateListener = new InitialStateListener();\r\n        discovery.addListener(initialStateListener);\r\n        discovery.start();\r\n        logger.info(discovery.nodeDescription());\r\n        try {\r\n            //NOCOMMIT\r\n            sleep(1000);\r\n        } catch (InterruptedException e) {\r\n\r\n        }\r\n    }\r\n```\r\n\r\nThe `NoMasterNodeTests` fail occasionally. It seems like sometimes the cluster is not blocked properly for writes. In addition, this makes all test in pr #9952 fail as described [here](https://github.com/elasticsearch/elasticsearch/pull/9952#issuecomment-77535805).\r\nI think this needs to be investigated."}}
{"actor":{"display_login":"brwe"}}