Skip to content

Commit

Permalink
Merge remote-tracking branch 'ce/release/2.8.x' into 2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Dec 19, 2023
2 parents 853c210 + 0733e36 commit 12700c1
Show file tree
Hide file tree
Showing 29 changed files with 888 additions and 475 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@

- **HTTP Log**: fix internal error during validating the schema if http_endpoint contains
userinfo but headers is empty [#9574](https://github.com/Kong/kong/pull/9574)
- Update the batch queues module so that queues no longer grow without bounds if
their consumers fail to process the entries. Instead, old batches are now dropped
and an error is logged.
[#10247](https://github.com/Kong/kong/pull/10247)

##### CLI

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG/unreleased/kong/11480.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
message: Fix a problem that abnormal socket connection will be reused when querying Postgres database.
type: bugfix
scope: Core
prs:
- 11480
jiras:
- "FTI-5322"
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/bump_dns_stale_ttl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: Bump `dns_stale_ttl` default to 1 hour so stale DNS record can be used for longer time in case of resolver downtime.
type: performance
scope: Configuration
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/fix_dns_blocking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: Eliminate asynchronous timer in syncQuery() to prevent hang risk
type: bugfix
scope: Core
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: Update the DNS client to follow configured timeouts in a more predictable manner
type: bugfix
scope: Core
2 changes: 1 addition & 1 deletion kong-2.8.4-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies = {
"luaxxhash >= 1.0",
"lua-protobuf == 0.3.3",
"lua-resty-worker-events == 1.0.0",
"lua-resty-healthcheck == 1.5.1",
"lua-resty-healthcheck == 1.5.3",
"lua-resty-mlcache == 2.5.0",
"lua-messagepack == 0.5.2",
"lua-resty-openssl == 0.8.22",
Expand Down
15 changes: 14 additions & 1 deletion kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -1312,14 +1312,16 @@
# property receives a value (in seconds), it
# will override the TTL for all records.

#dns_stale_ttl = 4 # Defines, in seconds, how long a record will
#dns_stale_ttl = 3600 # Defines, in seconds, how long a record will
# remain in cache past its TTL. This value
# will be used while the new DNS record is
# fetched in the background.
# Stale data will be used from expiry of a
# record until either the refresh query
# completes, or the `dns_stale_ttl` number of
# seconds have passed.
# This configuration enables Kong to be more
# resilient during resolver downtime.

#dns_cache_size = 10000 # Defines the maximum allowed number of
# DNS records stored in memory cache.
Expand Down Expand Up @@ -1560,3 +1562,14 @@
# **Warning**: Certain variables, when made
# available, may create opportunities to
# escape the sandbox.

#max_queued_batches = 100 # Maximum number of batches to keep on an internal
# plugin queue before dropping old batches. This is
# meant as a global, last-resort control to prevent
# queues from consuming infinite memory. When batches
# are being dropped, an error message
# "exceeded max_queued_batches (%d), dropping oldest"
# will be logged. The error message will also include
# a string that identifies the plugin causing the
# problem. Queues are used by the http-log, statsd,
# opentelemetry and datadog plugins.
2 changes: 2 additions & 0 deletions kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ local CONF_INFERENCES = {
untrusted_lua = { enum = { "on", "off", "sandbox" } },
untrusted_lua_sandbox_requires = { typ = "array" },
untrusted_lua_sandbox_environment = { typ = "array" },

max_queued_batches = { typ = "number" },
}


Expand Down
34 changes: 24 additions & 10 deletions kong/db/strategies/postgres/connector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ function _mt:query(sql, operation)
operation = "write"
end

local conn, is_new_conn
local res, err, partial, num_queries

local ok
Expand All @@ -505,23 +506,36 @@ function _mt:query(sql, operation)
return nil, "error acquiring query semaphore: " .. err
end

local conn = self:get_stored_connection(operation)
if conn then
res, err, partial, num_queries = conn:query(sql)

else
local connection
conn = self:get_stored_connection(operation)
if not conn then
local config = operation == "write" and self.config or self.config_ro

connection, err = connect(config)
if not connection then
conn, err = connect(config)
if not conn then
self:release_query_semaphore_resource(operation)
return nil, err
end
is_new_conn = true
end

res, err, partial, num_queries = conn:query(sql)

res, err, partial, num_queries = connection:query(sql)
-- if err is string then either it is a SQL error
-- or it is a socket error, here we abort connections
-- that encounter errors instead of reusing them, for
-- safety reason
if err and type(err) == "string" then
ngx.log(ngx.DEBUG, "SQL query throw error: ", err, ", close connection")
local _, err = conn:disconnect()
if err then
-- We're at the end of the query - just logging if
-- we cannot cleanup the connection
ngx.log(ngx.ERR, "failed to disconnect: ", err)
end
self.store_connection(nil, operation)

setkeepalive(connection)
elseif is_new_conn then
setkeepalive(conn)
end

self:release_query_semaphore_resource(operation)
Expand Down
31 changes: 20 additions & 11 deletions kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,12 @@ function Kong.init()

if config.role ~= "control_plane" then
assert(runloop.build_router("init"))

ok, err = runloop.set_init_versions_in_cache()
if not ok then
error("error setting initial versions for router and plugins iterator in cache: " ..
tostring(err))
end
end
end

Expand Down Expand Up @@ -638,12 +644,6 @@ function Kong.init_worker()
end
kong.core_cache = core_cache

ok, err = runloop.set_init_versions_in_cache()
if not ok then
stash_init_worker_error(err) -- 'err' fully formatted
return
end

-- LEGACY
singletons.cache = cache
singletons.core_cache = core_cache
Expand All @@ -661,22 +661,31 @@ function Kong.init_worker()
return
end

if kong.configuration.role ~= "control_plane" then
local is_not_control_plane = kong.configuration.role ~= "control_plane"
if is_not_control_plane then
ok, err = execute_cache_warmup(kong.configuration)
if not ok then
ngx_log(ngx_ERR, "failed to warm up the DB cache: " .. err)
end
end

runloop.init_worker.before()

-- run plugins init_worker context
ok, err = runloop.update_plugins_iterator()
if not ok then
stash_init_worker_error("failed to build the plugins iterator: " .. err)
return
end

if is_not_control_plane then
ok, err = runloop.update_router()
if not ok then
stash_init_worker_error("failed to build the router: " .. err)
return
end
end

runloop.init_worker.before()

-- run plugins init_worker context
local plugins_iterator = runloop.get_plugins_iterator()
local errors = execute_init_worker_plugins_iterator(plugins_iterator, ctx)
if errors then
Expand All @@ -689,7 +698,7 @@ function Kong.init_worker()

runloop.init_worker.after()

if kong.configuration.role ~= "control_plane" then
if is_not_control_plane and ngx.worker.id() == 0 then
plugin_servers.start()
end

Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/http-log/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function HttpLogHandler:log(conf)
}

local err
q, err = BatchQueue.new(process, opts)
q, err = BatchQueue.new("http-log", process, opts)
if not q then
kong.log.err("could not create queue: ", err)
return
Expand Down
Loading

0 comments on commit 12700c1

Please sign in to comment.