Skip to content

Commit

Permalink
fix(dbless) handle possible errors of declarative_init_build()
Browse files Browse the repository at this point in the history
  • Loading branch information
aboudreault committed May 25, 2022
1 parent b07d213 commit dc1f746
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 10 additions & 2 deletions kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,11 @@ function Kong.init_worker()
-- if there is no declarative config set and a config is present in LMDB,
-- just build the router and plugins iterator
ngx_log(ngx_INFO, "found persisted lmdb config, loading...")
declarative_init_build()
local ok, err = declarative_init_build()
if not ok then
stash_init_worker_error("failed to initialize declarative config: " .. err)
return
end
elseif declarative_entities then
ok, err = load_declarative_config(kong.configuration,
declarative_entities,
Expand All @@ -699,7 +703,11 @@ function Kong.init_worker()
else
-- stream does not need to load declarative config again, just build
-- the router and plugins iterator
declarative_init_build()
local ok, err = declarative_init_build()
if not ok then
stash_init_worker_error("failed to initialize declarative config: " .. err)
return
end
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/02-integration/11-dbless/03-config_persistence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe("dbless persistence with a declarative config #off", function()
database = "off",
declarative_config = yaml_file,
}))

admin_client = assert(helpers.admin_client())
proxy_client = assert(helpers.proxy_client())

Expand All @@ -105,10 +105,10 @@ describe("dbless persistence with a declarative config #off", function()
assert.res_status(201, res)
res = assert(proxy_client:get("/500", { headers = { host = "example1.dev" } }))
assert.res_status(401, res)

proxy_client:close()
end)

after_each(function()
if admin_client then
admin_client:close()
Expand All @@ -118,7 +118,7 @@ describe("dbless persistence with a declarative config #off", function()
end
helpers.stop_kong(nil, true)
end)

lazy_teardown(function()
os.remove(yaml_file)
end)
Expand All @@ -141,7 +141,7 @@ describe("dbless persistence with a declarative config #off", function()
database = "off",
declarative_config = yaml_file,
}))

local res
helpers.wait_until(function()
proxy_client = assert(helpers.proxy_client())
Expand Down

0 comments on commit dc1f746

Please sign in to comment.