{"action":"closed","issue":{"url":"https://api.github.com/repos/rails/actioncable/issues/74","labels_url":"https://api.github.com/repos/rails/actioncable/issues/74/labels{/name}","comments_url":"https://api.github.com/repos/rails/actioncable/issues/74/comments","events_url":"https://api.github.com/repos/rails/actioncable/issues/74/events","html_url":"https://github.com/rails/actioncable/issues/74","id":104992508,"number":74,"title":"Redis subscribed race condition","user":{"login":"smellsblue","id":150632,"avatar_url":"https://avatars.githubusercontent.com/u/150632?v=3","gravatar_id":"","url":"https://api.github.com/users/smellsblue","html_url":"https://github.com/smellsblue","followers_url":"https://api.github.com/users/smellsblue/followers","following_url":"https://api.github.com/users/smellsblue/following{/other_user}","gists_url":"https://api.github.com/users/smellsblue/gists{/gist_id}","starred_url":"https://api.github.com/users/smellsblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smellsblue/subscriptions","organizations_url":"https://api.github.com/users/smellsblue/orgs","repos_url":"https://api.github.com/users/smellsblue/repos","events_url":"https://api.github.com/users/smellsblue/events{/privacy}","received_events_url":"https://api.github.com/users/smellsblue/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"javan","id":5355,"avatar_url":"https://avatars.githubusercontent.com/u/5355?v=3","gravatar_id":"","url":"https://api.github.com/users/javan","html_url":"https://github.com/javan","followers_url":"https://api.github.com/users/javan/followers","following_url":"https://api.github.com/users/javan/following{/other_user}","gists_url":"https://api.github.com/users/javan/gists{/gist_id}","starred_url":"https://api.github.com/users/javan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javan/subscriptions","organizations_url":"https://api.github.com/users/javan/orgs","repos_url":"https://api.github.com/users/javan/repos","events_url":"https://api.github.com/users/javan/events{/privacy}","received_events_url":"https://api.github.com/users/javan/received_events","type":"User","site_admin":false},"milestone":null,"comments":4,"created_at":"2015-09-05T00:46:29Z","updated_at":"2015-12-14T19:23:00Z","closed_at":"2015-12-14T19:23:00Z","body":"I have a post action which in turn notifies a thread I have running to stop its processing. When the processing is complete, this in turn triggers some broadcast messages to tell the browser to update the view with some new details. The thread doesn't die right away, so after the redirect from the post, the old state will be visible until the ActionCable broadcast message comes in.\r\n\r\nUnfortunately, I am hitting a race condition... the browser reloads from the redirect, but then never gets the message with the new state. At first I thought this might be a race condition from between when the browser first loads to when the ActionCable websocket is actually connected. So, I listened for the consumer to be connected and pulled the state via a JSON request... thus I should (for sure) get the correct state after the redirect from the post:\r\n\r\n```coffee\r\nApp.myChannel = App.cable.subscriptions.create \"MyChannel\",\r\n  connected: ->\r\n    # ... call JSON request and update state\r\n\r\n  received: (data) ->\r\n    # ... update state\r\n```\r\n\r\nThis didn't solve the problem. So I dug a bit more and found that my redis subscription wasn't successfully subscribed until after my websocket was connected, and that was the race condition. I have a pull request that I will link to this issue which demonstrates a possible fix such that the following would solve my race condition:\r\n\r\n```coffee\r\nApp.myChannel = App.cable.subscriptions.create \"MyChannel\",\r\n  subscribed: ->\r\n    # ... call JSON request and update state\r\n\r\n  received: (data) ->\r\n    # ... update state\r\n```\r\n\r\nI realize my solution is a bit hacky and probably not the ultimate desired solution, but I would love to dig in and help with the final solution. Where would be the best place to discuss how this should actually be solved?"}}