{"action":"created","issue":{"url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/275","repository_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk","labels_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/275/labels{/name}","comments_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/275/comments","events_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/275/events","html_url":"https://github.com/matrix-org/matrix-js-sdk/issues/275","id":188324505,"number":275,"title":"room.currentState does not always get updated with new state","user":{"login":"freelock","id":46937,"avatar_url":"https://avatars.githubusercontent.com/u/46937?v=3","gravatar_id":"","url":"https://api.github.com/users/freelock","html_url":"https://github.com/freelock","followers_url":"https://api.github.com/users/freelock/followers","following_url":"https://api.github.com/users/freelock/following{/other_user}","gists_url":"https://api.github.com/users/freelock/gists{/gist_id}","starred_url":"https://api.github.com/users/freelock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freelock/subscriptions","organizations_url":"https://api.github.com/users/freelock/orgs","repos_url":"https://api.github.com/users/freelock/repos","events_url":"https://api.github.com/users/freelock/events{/privacy}","received_events_url":"https://api.github.com/users/freelock/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-11-09T18:57:50Z","updated_at":"2016-11-10T17:14:50Z","closed_at":null,"body":"Reported in #matrix-dev at https://matrix.to/#/!XqBunHwQIXUiqCaoxq:matrix.org/$14787151541517PqIir:matrix.freelock.com :\r\n\r\nMy bot calls matrixClient.startClient({initialSyncLimit: 1}) when it's started, and correctly sets the room.currentState on all the rooms it's a member of.\r\n\r\nIt listens to events on matrixClient.on(\"Room.timeline\", ...), and reacts to some of them using matrixClient.sendStateEvent() to set new states, sometimes many in a row.\r\n\r\nI have seen rate-limit errors, and have an error callback on the promise that waits for the specified timeout and then retries.\r\n\r\nThen, at some later point, new messages trigger the bot again -- but when it attempts to check the state previously set in sendStateEvent(), using room.currentState.getStateEvents(), sometimes it returns the value previously set, and not the new value.\r\n\r\nThis is not consistent -- most of the time it's working just fine, but we do see some states where the bot shows the old value.\r\n\r\nRestarting the bot results in it loading the state from the room in the /sync, and then it's showing the expected state -- this makes me think that the room state is getting set correctly, always, but the room.currentState is somehow caching the old value. Almost feels like a race condition.\r\n\r\nDave suggests checking for the state event coming through sync immediately after setting the state, to make sure that's all coming through -- I'll try to spend some time in the next week or two instrumenting this to find the problem."},"comment":{"url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/comments/259749985","html_url":"https://github.com/matrix-org/matrix-js-sdk/issues/275#issuecomment-259749985","issue_url":"https://api.github.com/repos/matrix-org/matrix-js-sdk/issues/275","id":259749985,"user":{"login":"richvdh","id":1389908,"avatar_url":"https://avatars.githubusercontent.com/u/1389908?v=3","gravatar_id":"","url":"https://api.github.com/users/richvdh","html_url":"https://github.com/richvdh","followers_url":"https://api.github.com/users/richvdh/followers","following_url":"https://api.github.com/users/richvdh/following{/other_user}","gists_url":"https://api.github.com/users/richvdh/gists{/gist_id}","starred_url":"https://api.github.com/users/richvdh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richvdh/subscriptions","organizations_url":"https://api.github.com/users/richvdh/orgs","repos_url":"https://api.github.com/users/richvdh/repos","events_url":"https://api.github.com/users/richvdh/events{/privacy}","received_events_url":"https://api.github.com/users/richvdh/received_events","type":"User","site_admin":false},"created_at":"2016-11-10T17:14:50Z","updated_at":"2016-11-10T17:14:50Z","body":"`currentState` is only updated from the `/sync` response, not on `sendStateEvent`. So I don't think the race you suggest is possible."}}
{"actor":{"display_login":"richvdh"}}