{"action":"created","comment":{"url":"https://api.github.com/repos/wikimedia/restbase/pulls/comments/62796833","id":62796833,"diff_hunk":"@@ -85,6 +85,26 @@ EventService.prototype._emit = function(hyper, req) {\n                 return event;\n             })\n             .filter(function(event) { return !!event; });\n+\n+            // Change-propagation will set up the x-rerender-reason header, indicating\n+            // the event which caused the rerender. In case RESTBase is about to emit\n+            // the same event, it will cause a rerender loop. So, log an error and skip\n+            // an event.\n+            var reRenderReason = req.headers && req.headers['x-rerender-reason']\n+                || hyper._rootReq && hyper._rootReq['x-rerender-reason'];\n+            if (reRenderReason) {\n+                events = events.filter(function(event) {\n+                    if (reRenderReason.replace(/^https?:/, '') === event.meta.uri.replace(/^https?:/, '')) {","path":"sys/events.js","position":13,"original_position":13,"commit_id":"e79b1b457b2d5ac5bfb887a6f9dbdb9608ec61a5","original_commit_id":"e79b1b457b2d5ac5bfb887a6f9dbdb9608ec61a5","user":{"login":"Pchelolo","id":814754,"avatar_url":"https://avatars.githubusercontent.com/u/814754?v=3","gravatar_id":"","url":"https://api.github.com/users/Pchelolo","html_url":"https://github.com/Pchelolo","followers_url":"https://api.github.com/users/Pchelolo/followers","following_url":"https://api.github.com/users/Pchelolo/following{/other_user}","gists_url":"https://api.github.com/users/Pchelolo/gists{/gist_id}","starred_url":"https://api.github.com/users/Pchelolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pchelolo/subscriptions","organizations_url":"https://api.github.com/users/Pchelolo/orgs","repos_url":"https://api.github.com/users/Pchelolo/repos","events_url":"https://api.github.com/users/Pchelolo/events{/privacy}","received_events_url":"https://api.github.com/users/Pchelolo/received_events","type":"User","site_admin":false},"body":"So, as a conclusion, we all agree we need to get the optional XFF-like field in meta in all events. \r\n\r\nAs for the regex - basically we're making sure that a loose `s` in https doesn't get us in trouble. Events in the extension are emitted the https, while restbase exists them with http.","created_at":"2016-05-11T06:24:31Z","updated_at":"2016-05-11T06:24:31Z","html_url":"https://github.com/wikimedia/restbase/pull/607#discussion_r62796833","pull_request_url":"https://api.github.com/repos/wikimedia/restbase/pulls/607","_links":{"self":{"href":"https://api.github.com/repos/wikimedia/restbase/pulls/comments/62796833"},"html":{"href":"https://github.com/wikimedia/restbase/pull/607#discussion_r62796833"},"pull_request":{"href":"https://api.github.com/repos/wikimedia/restbase/pulls/607"}}},"pull_request":{"url":"https://api.github.com/repos/wikimedia/restbase/pulls/607","id":69406735,"html_url":"https://github.com/wikimedia/restbase/pull/607","diff_url":"https://github.com/wikimedia/restbase/pull/607.diff","patch_url":"https://github.com/wikimedia/restbase/pull/607.patch","issue_url":"https://api.github.com/repos/wikimedia/restbase/issues/607","number":607,"state":"open","locked":false,"title":"Do not emit an event if it will cause a loop","user":{"login":"Pchelolo","id":814754,"avatar_url":"https://avatars.githubusercontent.com/u/814754?v=3","gravatar_id":"","url":"https://api.github.com/users/Pchelolo","html_url":"https://github.com/Pchelolo","followers_url":"https://api.github.com/users/Pchelolo/followers","following_url":"https://api.github.com/users/Pchelolo/following{/other_user}","gists_url":"https://api.github.com/users/Pchelolo/gists{/gist_id}","starred_url":"https://api.github.com/users/Pchelolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pchelolo/subscriptions","organizations_url":"https://api.github.com/users/Pchelolo/orgs","repos_url":"https://api.github.com/users/Pchelolo/repos","events_url":"https://api.github.com/users/Pchelolo/events{/privacy}","received_events_url":"https://api.github.com/users/Pchelolo/received_events","type":"User","site_admin":false},"body":"After [an outage](https://phabricator.wikimedia.org/T134537) we've discovered, that when change-prop is introduced, some bugs playing together might cause rerender loops in RESTBase, when change-prop serenaders some content, and it creates the same event that caused a rerender to happen. \r\n\r\nThis PR adds some protection against it - change-prop will add the `x-rerender-reason` header (name subject to a bike shed) to a RESTBase request, containing an original event URI (it's enough as RB only emits `resource_change` events). If we are about to emit the same event causing a cycle - log an error and drop the event.\r\n\r\nQuestions:\r\n1. What to use as an event hash. I think URI is enough, but suggestions are welcome\r\n2. This doesn't prevent multiple-step loops (event1 causes rerender1 causes event2 causes rerender2 causes event1). Do we want to support cases like that? As a generic way of preventing multi-step loops, we've had an idea to add something like an XFF header to the event meta to indicate the whole sequence of events that caused some event to fire. This could be useful for debugging as well as to prevent multi-step loops\r\n\r\nPS: need to add this header in change-propagation.\r\n\r\ncc @wikimedia/services ","created_at":"2016-05-09T20:38:22Z","updated_at":"2016-05-11T06:24:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e3924392b67002d20c0ed5494d42c00cde79925e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wikimedia/restbase/pulls/607/commits","review_comments_url":"https://api.github.com/repos/wikimedia/restbase/pulls/607/comments","review_comment_url":"https://api.github.com/repos/wikimedia/restbase/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wikimedia/restbase/issues/607/comments","statuses_url":"https://api.github.com/repos/wikimedia/restbase/statuses/e79b1b457b2d5ac5bfb887a6f9dbdb9608ec61a5","head":{"label":"Pchelolo:rerender_cause","ref":"rerender_cause","sha":"e79b1b457b2d5ac5bfb887a6f9dbdb9608ec61a5","user":{"login":"Pchelolo","id":814754,"avatar_url":"https://avatars.githubusercontent.com/u/814754?v=3","gravatar_id":"","url":"https://api.github.com/users/Pchelolo","html_url":"https://github.com/Pchelolo","followers_url":"https://api.github.com/users/Pchelolo/followers","following_url":"https://api.github.com/users/Pchelolo/following{/other_user}","gists_url":"https://api.github.com/users/Pchelolo/gists{/gist_id}","starred_url":"https://api.github.com/users/Pchelolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pchelolo/subscriptions","organizations_url":"https://api.github.com/users/Pchelolo/orgs","repos_url":"https://api.github.com/users/Pchelolo/repos","events_url":"https://api.github.com/users/Pchelolo/events{/privacy}","received_events_url":"https://api.github.com/users/Pchelolo/received_events","type":"User","site_admin":false},"repo":{"id":37933525,"name":"restbase","full_name":"Pchelolo/restbase","owner":{"login":"Pchelolo","id":814754,"avatar_url":"https://avatars.githubusercontent.com/u/814754?v=3","gravatar_id":"","url":"https://api.github.com/users/Pchelolo","html_url":"https://github.com/Pchelolo","followers_url":"https://api.github.com/users/Pchelolo/followers","following_url":"https://api.github.com/users/Pchelolo/following{/other_user}","gists_url":"https://api.github.com/users/Pchelolo/gists{/gist_id}","starred_url":"https://api.github.com/users/Pchelolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pchelolo/subscriptions","organizations_url":"https://api.github.com/users/Pchelolo/orgs","repos_url":"https://api.github.com/users/Pchelolo/repos","events_url":"https://api.github.com/users/Pchelolo/events{/privacy}","received_events_url":"https://api.github.com/users/Pchelolo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Pchelolo/restbase","description":"Distributed storage with REST API & dispatcher for backend services","fork":true,"url":"https://api.github.com/repos/Pchelolo/restbase","forks_url":"https://api.github.com/repos/Pchelolo/restbase/forks","keys_url":"https://api.github.com/repos/Pchelolo/restbase/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Pchelolo/restbase/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Pchelolo/restbase/teams","hooks_url":"https://api.github.com/repos/Pchelolo/restbase/hooks","issue_events_url":"https://api.github.com/repos/Pchelolo/restbase/issues/events{/number}","events_url":"https://api.github.com/repos/Pchelolo/restbase/events","assignees_url":"https://api.github.com/repos/Pchelolo/restbase/assignees{/user}","branches_url":"https://api.github.com/repos/Pchelolo/restbase/branches{/branch}","tags_url":"https://api.github.com/repos/Pchelolo/restbase/tags","blobs_url":"https://api.github.com/repos/Pchelolo/restbase/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Pchelolo/restbase/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Pchelolo/restbase/git/refs{/sha}","trees_url":"https://api.github.com/repos/Pchelolo/restbase/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Pchelolo/restbase/statuses/{sha}","languages_url":"https://api.github.com/repos/Pchelolo/restbase/languages","stargazers_url":"https://api.github.com/repos/Pchelolo/restbase/stargazers","contributors_url":"https://api.github.com/repos/Pchelolo/restbase/contributors","subscribers_url":"https://api.github.com/repos/Pchelolo/restbase/subscribers","subscription_url":"https://api.github.com/repos/Pchelolo/restbase/subscription","commits_url":"https://api.github.com/repos/Pchelolo/restbase/commits{/sha}","git_commits_url":"https://api.github.com/repos/Pchelolo/restbase/git/commits{/sha}","comments_url":"https://api.github.com/repos/Pchelolo/restbase/comments{/number}","issue_comment_url":"https://api.github.com/repos/Pchelolo/restbase/issues/comments{/number}","contents_url":"https://api.github.com/repos/Pchelolo/restbase/contents/{+path}","compare_url":"https://api.github.com/repos/Pchelolo/restbase/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Pchelolo/restbase/merges","archive_url":"https://api.github.com/repos/Pchelolo/restbase/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Pchelolo/restbase/downloads","issues_url":"https://api.github.com/repos/Pchelolo/restbase/issues{/number}","pulls_url":"https://api.github.com/repos/Pchelolo/restbase/pulls{/number}","milestones_url":"https://api.github.com/repos/Pchelolo/restbase/milestones{/number}","notifications_url":"https://api.github.com/repos/Pchelolo/restbase/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Pchelolo/restbase/labels{/name}","releases_url":"https://api.github.com/repos/Pchelolo/restbase/releases{/id}","deployments_url":"https://api.github.com/repos/Pchelolo/restbase/deployments","created_at":"2015-06-23T17:22:56Z","updated_at":"2016-01-12T00:04:25Z","pushed_at":"2016-05-09T20:38:08Z","git_url":"git://github.com/Pchelolo/restbase.git","ssh_url":"git@github.com:Pchelolo/restbase.git","clone_url":"https://github.com/Pchelolo/restbase.git","svn_url":"https://github.com/Pchelolo/restbase","homepage":"https://www.mediawiki.org/wiki/RESTBase","size":2847,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"wikimedia:master","ref":"master","sha":"01c68ca602119b1639b5eb15526f807f6d00975e","user":{"login":"wikimedia","id":56668,"avatar_url":"https://avatars.githubusercontent.com/u/56668?v=3","gravatar_id":"","url":"https://api.github.com/users/wikimedia","html_url":"https://github.com/wikimedia","followers_url":"https://api.github.com/users/wikimedia/followers","following_url":"https://api.github.com/users/wikimedia/following{/other_user}","gists_url":"https://api.github.com/users/wikimedia/gists{/gist_id}","starred_url":"https://api.github.com/users/wikimedia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wikimedia/subscriptions","organizations_url":"https://api.github.com/users/wikimedia/orgs","repos_url":"https://api.github.com/users/wikimedia/repos","events_url":"https://api.github.com/users/wikimedia/events{/privacy}","received_events_url":"https://api.github.com/users/wikimedia/received_events","type":"Organization","site_admin":false},"repo":{"id":19002414,"name":"restbase","full_name":"wikimedia/restbase","owner":{"login":"wikimedia","id":56668,"avatar_url":"https://avatars.githubusercontent.com/u/56668?v=3","gravatar_id":"","url":"https://api.github.com/users/wikimedia","html_url":"https://github.com/wikimedia","followers_url":"https://api.github.com/users/wikimedia/followers","following_url":"https://api.github.com/users/wikimedia/following{/other_user}","gists_url":"https://api.github.com/users/wikimedia/gists{/gist_id}","starred_url":"https://api.github.com/users/wikimedia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wikimedia/subscriptions","organizations_url":"https://api.github.com/users/wikimedia/orgs","repos_url":"https://api.github.com/users/wikimedia/repos","events_url":"https://api.github.com/users/wikimedia/events{/privacy}","received_events_url":"https://api.github.com/users/wikimedia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wikimedia/restbase","description":"Distributed storage with REST API & dispatcher for backend services","fork":false,"url":"https://api.github.com/repos/wikimedia/restbase","forks_url":"https://api.github.com/repos/wikimedia/restbase/forks","keys_url":"https://api.github.com/repos/wikimedia/restbase/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wikimedia/restbase/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wikimedia/restbase/teams","hooks_url":"https://api.github.com/repos/wikimedia/restbase/hooks","issue_events_url":"https://api.github.com/repos/wikimedia/restbase/issues/events{/number}","events_url":"https://api.github.com/repos/wikimedia/restbase/events","assignees_url":"https://api.github.com/repos/wikimedia/restbase/assignees{/user}","branches_url":"https://api.github.com/repos/wikimedia/restbase/branches{/branch}","tags_url":"https://api.github.com/repos/wikimedia/restbase/tags","blobs_url":"https://api.github.com/repos/wikimedia/restbase/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wikimedia/restbase/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wikimedia/restbase/git/refs{/sha}","trees_url":"https://api.github.com/repos/wikimedia/restbase/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wikimedia/restbase/statuses/{sha}","languages_url":"https://api.github.com/repos/wikimedia/restbase/languages","stargazers_url":"https://api.github.com/repos/wikimedia/restbase/stargazers","contributors_url":"https://api.github.com/repos/wikimedia/restbase/contributors","subscribers_url":"https://api.github.com/repos/wikimedia/restbase/subscribers","subscription_url":"https://api.github.com/repos/wikimedia/restbase/subscription","commits_url":"https://api.github.com/repos/wikimedia/restbase/commits{/sha}","git_commits_url":"https://api.github.com/repos/wikimedia/restbase/git/commits{/sha}","comments_url":"https://api.github.com/repos/wikimedia/restbase/comments{/number}","issue_comment_url":"https://api.github.com/repos/wikimedia/restbase/issues/comments{/number}","contents_url":"https://api.github.com/repos/wikimedia/restbase/contents/{+path}","compare_url":"https://api.github.com/repos/wikimedia/restbase/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wikimedia/restbase/merges","archive_url":"https://api.github.com/repos/wikimedia/restbase/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wikimedia/restbase/downloads","issues_url":"https://api.github.com/repos/wikimedia/restbase/issues{/number}","pulls_url":"https://api.github.com/repos/wikimedia/restbase/pulls{/number}","milestones_url":"https://api.github.com/repos/wikimedia/restbase/milestones{/number}","notifications_url":"https://api.github.com/repos/wikimedia/restbase/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wikimedia/restbase/labels{/name}","releases_url":"https://api.github.com/repos/wikimedia/restbase/releases{/id}","deployments_url":"https://api.github.com/repos/wikimedia/restbase/deployments","created_at":"2014-04-21T18:35:00Z","updated_at":"2016-04-08T15:24:10Z","pushed_at":"2016-05-11T00:53:58Z","git_url":"git://github.com/wikimedia/restbase.git","ssh_url":"git@github.com:wikimedia/restbase.git","clone_url":"https://github.com/wikimedia/restbase.git","svn_url":"https://github.com/wikimedia/restbase","homepage":"https://www.mediawiki.org/wiki/RESTBase","size":3022,"stargazers_count":41,"watchers_count":41,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":28,"mirror_url":null,"open_issues_count":13,"forks":28,"open_issues":13,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wikimedia/restbase/pulls/607"},"html":{"href":"https://github.com/wikimedia/restbase/pull/607"},"issue":{"href":"https://api.github.com/repos/wikimedia/restbase/issues/607"},"comments":{"href":"https://api.github.com/repos/wikimedia/restbase/issues/607/comments"},"review_comments":{"href":"https://api.github.com/repos/wikimedia/restbase/pulls/607/comments"},"review_comment":{"href":"https://api.github.com/repos/wikimedia/restbase/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wikimedia/restbase/pulls/607/commits"},"statuses":{"href":"https://api.github.com/repos/wikimedia/restbase/statuses/e79b1b457b2d5ac5bfb887a6f9dbdb9608ec61a5"}}}}