Skip to content

Commit

Permalink
hotfix(core) run shms check in early init phase
Browse files Browse the repository at this point in the history
Some shms, and especially the `kong` one might be used inside of the
global patches (or in any of the other modules we require for that is).

This bug was caught on the CI environment with OpenResty 1.11.2.1, which
calls `math.randomseed()` inside of its main chunk from the
lua-resty-dns library, which triggers our custom
`globalpatches.randomseed` behavior, which needs the `kong` shm.
  • Loading branch information
thibaultcha committed May 1, 2017
1 parent ac19b71 commit 64f9fcd
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions kong/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@
-- |[[ ]]|
-- ==========

do
-- let's ensure the required shared dictionaries are
-- declared via lua_shared_dict in the Nginx conf

local constants = require "kong.constants"

for _, dict in ipairs(constants.DICTS) do
if not ngx.shared[dict] then
return error("missing shared dict '" .. dict .. "' in Nginx " ..
"configuration, are you using a custom template? " ..
"Make sure the 'lua_shared_dict " .. dict .. " [SIZE];' " ..
"directive is defined.")
end
end
end

require("kong.core.globalpatches")()

local dns = require "kong.tools.dns"
Expand Down Expand Up @@ -121,17 +137,6 @@ end
local Kong = {}

function Kong.init()
-- let's ensure the required shared dictionaries are
-- declared via lua_shared_dict in the Nginx conf
for _, dict in ipairs(constants.DICTS) do
if not ngx.shared[dict] then
return error("missing shared dict '" .. dict .. "' in Nginx " ..
"configuration, are you using a custom template? " ..
"Make sure the 'lua_shared_dict " .. dict .. " [SIZE];' " ..
"directive is defined.")
end
end

local pl_path = require "pl.path"
local conf_loader = require "kong.conf_loader"

Expand Down

0 comments on commit 64f9fcd

Please sign in to comment.