{"action":"created","issue":{"url":"https://api.github.com/repos/andrewgodwin/channels/issues/120","repository_url":"https://api.github.com/repos/andrewgodwin/channels","labels_url":"https://api.github.com/repos/andrewgodwin/channels/issues/120/labels{/name}","comments_url":"https://api.github.com/repos/andrewgodwin/channels/issues/120/comments","events_url":"https://api.github.com/repos/andrewgodwin/channels/issues/120/events","html_url":"https://github.com/andrewgodwin/channels/issues/120","id":146283499,"number":120,"title":"websocket.ws_receive is called before websocket.ws_connect","user":{"login":"darklow","id":445304,"avatar_url":"https://avatars.githubusercontent.com/u/445304?v=3","gravatar_id":"","url":"https://api.github.com/users/darklow","html_url":"https://github.com/darklow","followers_url":"https://api.github.com/users/darklow/followers","following_url":"https://api.github.com/users/darklow/following{/other_user}","gists_url":"https://api.github.com/users/darklow/gists{/gist_id}","starred_url":"https://api.github.com/users/darklow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darklow/subscriptions","organizations_url":"https://api.github.com/users/darklow/orgs","repos_url":"https://api.github.com/users/darklow/repos","events_url":"https://api.github.com/users/darklow/events{/privacy}","received_events_url":"https://api.github.com/users/darklow/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-06T11:30:49Z","updated_at":"2016-04-06T14:28:08Z","closed_at":null,"body":"In specific case `websocket.ws_receive` is called before `websocket.ws_connect`.\r\nIn normal scenario everythings works fine.\r\nBut if on the client side I use automatic reconnection onclose and as soon as websocket is connected again send message immediately then in Django i got both calls in reversed order `ws_receive` first, in which case I cannot get authorized user anymore.\r\n\r\nIt easy to test if i restart Django runserver while client is connected, then connection from client side is lost and as soon as connection is established i see following in my console:\r\n```\r\nChannel layer default (asgi_redis.RedisChannelLayer)\r\nQuit the server with CONTROL-C.\r\n\r\n[2016/04/06 06:27:48] WebSocket CONNECT /forum/ [127.0.0.1:49565]\r\nWS_RECEIVE:  2016-04-06 11:27:48.194518+00:00 AnonymousUser       <<< This comes first and without user\r\nWS_CONNECT:  2016-04-06 11:27:48.201150+00:00 Kaspars Sprogis\r\n[2016/04/06 06:27:48] WebSocket CONNECT /forum/ [127.0.0.1:49570]\r\nWS_CONNECT:  2016-04-06 11:27:48.362870+00:00 Kaspars Sprogis\r\n```\r\n\r\nThis is my `consumers.py`:\r\n```py\r\n\r\nfrom channels.auth import channel_session_user, channel_session_user_from_http\r\n\r\n@channel_session_user_from_http\r\ndef ws_connect(message):\r\n    print 'WS_CONNECT: ', now(), message.user\r\n\r\n@channel_session_user\r\ndef ws_receive(message):\r\n    print 'WS_RECEIVE: ', now(), message.user\r\n\r\n```\r\n\r\nAny ideas how to resolve this or why this happens?\r\n\r\nSeeing duplicate /connect/ event is also interesting, however on client/JS side all events happen in correct order.\r\n```\r\nwaiting...\r\nwaiting...\r\nonOpen / socket.readyState = 1\r\nsending message...\r\n```\r\nThank you."},"comment":{"url":"https://api.github.com/repos/andrewgodwin/channels/issues/comments/206400176","html_url":"https://github.com/andrewgodwin/channels/issues/120#issuecomment-206400176","issue_url":"https://api.github.com/repos/andrewgodwin/channels/issues/120","id":206400176,"user":{"login":"sachinrekhi","id":192650,"avatar_url":"https://avatars.githubusercontent.com/u/192650?v=3","gravatar_id":"","url":"https://api.github.com/users/sachinrekhi","html_url":"https://github.com/sachinrekhi","followers_url":"https://api.github.com/users/sachinrekhi/followers","following_url":"https://api.github.com/users/sachinrekhi/following{/other_user}","gists_url":"https://api.github.com/users/sachinrekhi/gists{/gist_id}","starred_url":"https://api.github.com/users/sachinrekhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sachinrekhi/subscriptions","organizations_url":"https://api.github.com/users/sachinrekhi/orgs","repos_url":"https://api.github.com/users/sachinrekhi/repos","events_url":"https://api.github.com/users/sachinrekhi/events{/privacy}","received_events_url":"https://api.github.com/users/sachinrekhi/received_events","type":"User","site_admin":false},"created_at":"2016-04-06T14:28:08Z","updated_at":"2016-04-06T14:28:08Z","body":"You need to use the enforce_ordering decorator to prevent this, as described here: https://channels.readthedocs.org/en/latest/getting-started.html#enforcing-ordering"}}