{"action":"created","comment":{"url":"https://api.github.com/repos/Kong/kong/pulls/comments/219312152","pull_request_review_id":157458047,"id":219312152,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxOTMxMjE1Mg==","diff_hunk":"@@ -435,13 +456,45 @@ return {\n         log(ngx.CRIT, \"could not ensure API router is up to date: \", err)\n \n       elseif api_router_version ~= version then\n-        log(DEBUG, \"rebuilding API router\")\n \n-        local ok, err = build_api_router(singletons.dao, version)\n+        -- wrap api_router rebuilds in a per-worker mutex (via ngx.semaphore)\n+        -- this prevents dogpiling the database during rebuilds in\n+        -- high-concurrency traffic patterns\n+        -- requests that arrive on this process during a api_router rebuild will be\n+        -- queued. once the semaphore resource is acquired we re-check the\n+        -- api_router version again to prevent unnecessary subsequent rebuilds\n+        --\n+        -- note the ten-second wait() timeout. we should be able to safely assume\n+        -- that a api_router rebuild event should never take this long\n+\n+        local ok, err = build_api_router_semaphore:wait(10)\n         if not ok then\n-          api_router_err = err\n-          log(ngx.CRIT, \"could not rebuild API router: \", err)\n+          return responses.send_HTTP_INTERNAL_SERVER_ERROR(\n+            \"error attempting to acquire build_api_router lock: \" .. err\n+          )\n         end\n+\n+        -- lock acquired but we might not need to rebuild the api_router (if we were\n+        -- not the first request in this process to enter this code path)\n+        -- check again and rebuild if necessary\n+\n+        version, err = cache:get(\"api_router:version\", CACHE_ROUTER_OPTS, utils.uuid)\n+        if err then\n+          log(ngx.CRIT, \"could not ensure api_router is up to date: \", err)\n+\n+        elseif api_router_version ~= version then\n+","path":"kong/runloop/handler.lua","position":86,"original_position":86,"commit_id":"9e1bba4855f19deb6bbe2ff0d15029c643d13ec3","original_commit_id":"9e1bba4855f19deb6bbe2ff0d15029c643d13ec3","user":{"login":"thibaultcha","id":1125431,"node_id":"MDQ6VXNlcjExMjU0MzE=","avatar_url":"https://avatars2.githubusercontent.com/u/1125431?v=4","gravatar_id":"","url":"https://api.github.com/users/thibaultcha","html_url":"https://github.com/thibaultcha","followers_url":"https://api.github.com/users/thibaultcha/followers","following_url":"https://api.github.com/users/thibaultcha/following{/other_user}","gists_url":"https://api.github.com/users/thibaultcha/gists{/gist_id}","starred_url":"https://api.github.com/users/thibaultcha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thibaultcha/subscriptions","organizations_url":"https://api.github.com/users/thibaultcha/orgs","repos_url":"https://api.github.com/users/thibaultcha/repos","events_url":"https://api.github.com/users/thibaultcha/events{/privacy}","received_events_url":"https://api.github.com/users/thibaultcha/received_events","type":"User","site_admin":false},"body":"Mind getting rid of this blank line (in both Routes and APIs code paths)?","created_at":"2018-09-20T20:46:44Z","updated_at":"2018-09-20T20:48:01Z","html_url":"https://github.com/Kong/kong/pull/3782#discussion_r219312152","pull_request_url":"https://api.github.com/repos/Kong/kong/pulls/3782","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/Kong/kong/pulls/comments/219312152"},"html":{"href":"https://github.com/Kong/kong/pull/3782#discussion_r219312152"},"pull_request":{"href":"https://api.github.com/repos/Kong/kong/pulls/3782"}}},"pull_request":{"url":"https://api.github.com/repos/Kong/kong/pulls/3782","id":216046125,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE2MDQ2MTI1","html_url":"https://github.com/Kong/kong/pull/3782","diff_url":"https://github.com/Kong/kong/pull/3782.diff","patch_url":"https://github.com/Kong/kong/pull/3782.patch","issue_url":"https://api.github.com/repos/Kong/kong/issues/3782","number":3782,"state":"open","locked":false,"title":"perf(router) wrap router rebuilds in a mutex","user":{"login":"p0pr0ck5","id":4625425,"node_id":"MDQ6VXNlcjQ2MjU0MjU=","avatar_url":"https://avatars0.githubusercontent.com/u/4625425?v=4","gravatar_id":"","url":"https://api.github.com/users/p0pr0ck5","html_url":"https://github.com/p0pr0ck5","followers_url":"https://api.github.com/users/p0pr0ck5/followers","following_url":"https://api.github.com/users/p0pr0ck5/following{/other_user}","gists_url":"https://api.github.com/users/p0pr0ck5/gists{/gist_id}","starred_url":"https://api.github.com/users/p0pr0ck5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p0pr0ck5/subscriptions","organizations_url":"https://api.github.com/users/p0pr0ck5/orgs","repos_url":"https://api.github.com/users/p0pr0ck5/repos","events_url":"https://api.github.com/users/p0pr0ck5/events{/privacy}","received_events_url":"https://api.github.com/users/p0pr0ck5/received_events","type":"User","site_admin":false},"body":"Guard calls to build_router in a worker-level mutex (via\r\nngx.semaphore) in order to prevent database dogpiling during\r\nrebuild events in high-concurrency traffic patterns. Requests\r\non a worker process rebuilding the router will be queued and resumed\r\nonce the rebuild is complete.\r\n\r\n### Full Changelog\r\n\r\n* wrap build_router calls in a worker-level mutex\r\n\r\n### Issues resolved\r\n\r\nFix #3634 ","created_at":"2018-09-17T16:45:33Z","updated_at":"2018-09-20T20:48:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"93f3dfa48bd3289914e3cd51fe423b5bf59345cb","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":219207429,"node_id":"MDU6TGFiZWwyMTkyMDc0Mjk=","url":"https://api.github.com/repos/Kong/kong/labels/pr/please%20review","name":"pr/please review","color":"8c48ea","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/Kong/kong/pulls/3782/commits","review_comments_url":"https://api.github.com/repos/Kong/kong/pulls/3782/comments","review_comment_url":"https://api.github.com/repos/Kong/kong/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Kong/kong/issues/3782/comments","statuses_url":"https://api.github.com/repos/Kong/kong/statuses/9e1bba4855f19deb6bbe2ff0d15029c643d13ec3","head":{"label":"Kong:perf/router-rebuild-mutex","ref":"perf/router-rebuild-mutex","sha":"9e1bba4855f19deb6bbe2ff0d15029c643d13ec3","user":{"login":"Kong","id":962416,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk2MjQxNg==","avatar_url":"https://avatars0.githubusercontent.com/u/962416?v=4","gravatar_id":"","url":"https://api.github.com/users/Kong","html_url":"https://github.com/Kong","followers_url":"https://api.github.com/users/Kong/followers","following_url":"https://api.github.com/users/Kong/following{/other_user}","gists_url":"https://api.github.com/users/Kong/gists{/gist_id}","starred_url":"https://api.github.com/users/Kong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kong/subscriptions","organizations_url":"https://api.github.com/users/Kong/orgs","repos_url":"https://api.github.com/users/Kong/repos","events_url":"https://api.github.com/users/Kong/events{/privacy}","received_events_url":"https://api.github.com/users/Kong/received_events","type":"Organization","site_admin":false},"repo":{"id":26783295,"node_id":"MDEwOlJlcG9zaXRvcnkyNjc4MzI5NQ==","name":"kong","full_name":"Kong/kong","private":false,"owner":{"login":"Kong","id":962416,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk2MjQxNg==","avatar_url":"https://avatars0.githubusercontent.com/u/962416?v=4","gravatar_id":"","url":"https://api.github.com/users/Kong","html_url":"https://github.com/Kong","followers_url":"https://api.github.com/users/Kong/followers","following_url":"https://api.github.com/users/Kong/following{/other_user}","gists_url":"https://api.github.com/users/Kong/gists{/gist_id}","starred_url":"https://api.github.com/users/Kong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kong/subscriptions","organizations_url":"https://api.github.com/users/Kong/orgs","repos_url":"https://api.github.com/users/Kong/repos","events_url":"https://api.github.com/users/Kong/events{/privacy}","received_events_url":"https://api.github.com/users/Kong/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/Kong/kong","description":":gorilla: The Cloud-Native API Gateway","fork":false,"url":"https://api.github.com/repos/Kong/kong","forks_url":"https://api.github.com/repos/Kong/kong/forks","keys_url":"https://api.github.com/repos/Kong/kong/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Kong/kong/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Kong/kong/teams","hooks_url":"https://api.github.com/repos/Kong/kong/hooks","issue_events_url":"https://api.github.com/repos/Kong/kong/issues/events{/number}","events_url":"https://api.github.com/repos/Kong/kong/events","assignees_url":"https://api.github.com/repos/Kong/kong/assignees{/user}","branches_url":"https://api.github.com/repos/Kong/kong/branches{/branch}","tags_url":"https://api.github.com/repos/Kong/kong/tags","blobs_url":"https://api.github.com/repos/Kong/kong/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Kong/kong/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Kong/kong/git/refs{/sha}","trees_url":"https://api.github.com/repos/Kong/kong/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Kong/kong/statuses/{sha}","languages_url":"https://api.github.com/repos/Kong/kong/languages","stargazers_url":"https://api.github.com/repos/Kong/kong/stargazers","contributors_url":"https://api.github.com/repos/Kong/kong/contributors","subscribers_url":"https://api.github.com/repos/Kong/kong/subscribers","subscription_url":"https://api.github.com/repos/Kong/kong/subscription","commits_url":"https://api.github.com/repos/Kong/kong/commits{/sha}","git_commits_url":"https://api.github.com/repos/Kong/kong/git/commits{/sha}","comments_url":"https://api.github.com/repos/Kong/kong/comments{/number}","issue_comment_url":"https://api.github.com/repos/Kong/kong/issues/comments{/number}","contents_url":"https://api.github.com/repos/Kong/kong/contents/{+path}","compare_url":"https://api.github.com/repos/Kong/kong/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Kong/kong/merges","archive_url":"https://api.github.com/repos/Kong/kong/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Kong/kong/downloads","issues_url":"https://api.github.com/repos/Kong/kong/issues{/number}","pulls_url":"https://api.github.com/repos/Kong/kong/pulls{/number}","milestones_url":"https://api.github.com/repos/Kong/kong/milestones{/number}","notifications_url":"https://api.github.com/repos/Kong/kong/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Kong/kong/labels{/name}","releases_url":"https://api.github.com/repos/Kong/kong/releases{/id}","deployments_url":"https://api.github.com/repos/Kong/kong/deployments","created_at":"2014-11-17T23:56:08Z","updated_at":"2018-09-20T19:49:04Z","pushed_at":"2018-09-20T19:10:58Z","git_url":"git://github.com/Kong/kong.git","ssh_url":"git@github.com:Kong/kong.git","clone_url":"https://github.com/Kong/kong.git","svn_url":"https://github.com/Kong/kong","homepage":"https://konghq.com/install","size":10056,"stargazers_count":17859,"watchers_count":17859,"language":"Lua","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2084,"mirror_url":null,"archived":false,"open_issues_count":292,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":2084,"open_issues":292,"watchers":17859,"default_branch":"master"}},"base":{"label":"Kong:master","ref":"master","sha":"2fc857e23f4ac27903222d26ee8cae3191c878fa","user":{"login":"Kong","id":962416,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk2MjQxNg==","avatar_url":"https://avatars0.githubusercontent.com/u/962416?v=4","gravatar_id":"","url":"https://api.github.com/users/Kong","html_url":"https://github.com/Kong","followers_url":"https://api.github.com/users/Kong/followers","following_url":"https://api.github.com/users/Kong/following{/other_user}","gists_url":"https://api.github.com/users/Kong/gists{/gist_id}","starred_url":"https://api.github.com/users/Kong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kong/subscriptions","organizations_url":"https://api.github.com/users/Kong/orgs","repos_url":"https://api.github.com/users/Kong/repos","events_url":"https://api.github.com/users/Kong/events{/privacy}","received_events_url":"https://api.github.com/users/Kong/received_events","type":"Organization","site_admin":false},"repo":{"id":26783295,"node_id":"MDEwOlJlcG9zaXRvcnkyNjc4MzI5NQ==","name":"kong","full_name":"Kong/kong","private":false,"owner":{"login":"Kong","id":962416,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk2MjQxNg==","avatar_url":"https://avatars0.githubusercontent.com/u/962416?v=4","gravatar_id":"","url":"https://api.github.com/users/Kong","html_url":"https://github.com/Kong","followers_url":"https://api.github.com/users/Kong/followers","following_url":"https://api.github.com/users/Kong/following{/other_user}","gists_url":"https://api.github.com/users/Kong/gists{/gist_id}","starred_url":"https://api.github.com/users/Kong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kong/subscriptions","organizations_url":"https://api.github.com/users/Kong/orgs","repos_url":"https://api.github.com/users/Kong/repos","events_url":"https://api.github.com/users/Kong/events{/privacy}","received_events_url":"https://api.github.com/users/Kong/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/Kong/kong","description":":gorilla: The Cloud-Native API Gateway","fork":false,"url":"https://api.github.com/repos/Kong/kong","forks_url":"https://api.github.com/repos/Kong/kong/forks","keys_url":"https://api.github.com/repos/Kong/kong/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Kong/kong/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Kong/kong/teams","hooks_url":"https://api.github.com/repos/Kong/kong/hooks","issue_events_url":"https://api.github.com/repos/Kong/kong/issues/events{/number}","events_url":"https://api.github.com/repos/Kong/kong/events","assignees_url":"https://api.github.com/repos/Kong/kong/assignees{/user}","branches_url":"https://api.github.com/repos/Kong/kong/branches{/branch}","tags_url":"https://api.github.com/repos/Kong/kong/tags","blobs_url":"https://api.github.com/repos/Kong/kong/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Kong/kong/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Kong/kong/git/refs{/sha}","trees_url":"https://api.github.com/repos/Kong/kong/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Kong/kong/statuses/{sha}","languages_url":"https://api.github.com/repos/Kong/kong/languages","stargazers_url":"https://api.github.com/repos/Kong/kong/stargazers","contributors_url":"https://api.github.com/repos/Kong/kong/contributors","subscribers_url":"https://api.github.com/repos/Kong/kong/subscribers","subscription_url":"https://api.github.com/repos/Kong/kong/subscription","commits_url":"https://api.github.com/repos/Kong/kong/commits{/sha}","git_commits_url":"https://api.github.com/repos/Kong/kong/git/commits{/sha}","comments_url":"https://api.github.com/repos/Kong/kong/comments{/number}","issue_comment_url":"https://api.github.com/repos/Kong/kong/issues/comments{/number}","contents_url":"https://api.github.com/repos/Kong/kong/contents/{+path}","compare_url":"https://api.github.com/repos/Kong/kong/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Kong/kong/merges","archive_url":"https://api.github.com/repos/Kong/kong/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Kong/kong/downloads","issues_url":"https://api.github.com/repos/Kong/kong/issues{/number}","pulls_url":"https://api.github.com/repos/Kong/kong/pulls{/number}","milestones_url":"https://api.github.com/repos/Kong/kong/milestones{/number}","notifications_url":"https://api.github.com/repos/Kong/kong/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Kong/kong/labels{/name}","releases_url":"https://api.github.com/repos/Kong/kong/releases{/id}","deployments_url":"https://api.github.com/repos/Kong/kong/deployments","created_at":"2014-11-17T23:56:08Z","updated_at":"2018-09-20T19:49:04Z","pushed_at":"2018-09-20T19:10:58Z","git_url":"git://github.com/Kong/kong.git","ssh_url":"git@github.com:Kong/kong.git","clone_url":"https://github.com/Kong/kong.git","svn_url":"https://github.com/Kong/kong","homepage":"https://konghq.com/install","size":10056,"stargazers_count":17859,"watchers_count":17859,"language":"Lua","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2084,"mirror_url":null,"archived":false,"open_issues_count":292,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":2084,"open_issues":292,"watchers":17859,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Kong/kong/pulls/3782"},"html":{"href":"https://github.com/Kong/kong/pull/3782"},"issue":{"href":"https://api.github.com/repos/Kong/kong/issues/3782"},"comments":{"href":"https://api.github.com/repos/Kong/kong/issues/3782/comments"},"review_comments":{"href":"https://api.github.com/repos/Kong/kong/pulls/3782/comments"},"review_comment":{"href":"https://api.github.com/repos/Kong/kong/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Kong/kong/pulls/3782/commits"},"statuses":{"href":"https://api.github.com/repos/Kong/kong/statuses/9e1bba4855f19deb6bbe2ff0d15029c643d13ec3"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"thibaultcha"}}