From 30c0c823e8a63e974c0f0af626ddc1e97265aafa Mon Sep 17 00:00:00 2001 From: Yufu Zhao Date: Mon, 6 May 2024 16:05:15 +0800 Subject: [PATCH] fix(cmd): do not override `kong.conf` if `--db-timeout` is not passed (#12761) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit explicitly Prior to this fix, if the gateway was started using the kong cli, the final `pg_timeout` would be overridden to `60s` instead of the value specified in `kong.conf`, even if `--db-timeout` was not explicitly passed in. This was fixed by making cli args `--db-timeout` optional, so that only explicitly passed in arguments would override the `pg_timeout` otherwise the value specified in `kong.conf` would continue to be used. Co-authored-by: Hans Hübner (cherry picked from commit fd8707ee6a505fecfc388997863c573398b2b853) --- changelog/unreleased/kong/fix-cli-db-timeout-overrides.yml | 5 +++++ kong/cmd/migrations.lua | 6 +++--- kong/cmd/restart.lua | 2 +- kong/cmd/start.lua | 6 +++--- 4 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 changelog/unreleased/kong/fix-cli-db-timeout-overrides.yml diff --git a/changelog/unreleased/kong/fix-cli-db-timeout-overrides.yml b/changelog/unreleased/kong/fix-cli-db-timeout-overrides.yml new file mode 100644 index 000000000000..3db26988e38d --- /dev/null +++ b/changelog/unreleased/kong/fix-cli-db-timeout-overrides.yml @@ -0,0 +1,5 @@ +message: | + Fixed an issue where the `pg_timeout` was overridden to `60s` even if `--db-timeout` + was not explicitly passed in CLI arguments. +type: bugfix +scope: CLI Command diff --git a/kong/cmd/migrations.lua b/kong/cmd/migrations.lua index fa01c65422b7..bee5a90d7441 100644 --- a/kong/cmd/migrations.lua +++ b/kong/cmd/migrations.lua @@ -37,7 +37,7 @@ Options: -f,--force Run migrations even if database reports as already executed. - --db-timeout (default 60) Timeout, in seconds, for all database + --db-timeout (optional number) Timeout, in seconds, for all database operations. @@ -77,7 +77,7 @@ end local function execute(args) - args.db_timeout = args.db_timeout * 1000 + args.db_timeout = args.db_timeout and (args.db_timeout * 1000) or nil args.lock_timeout = args.lock_timeout if args.quiet then @@ -90,7 +90,7 @@ local function execute(args) package.path = conf.lua_package_path .. ";" .. package.path - conf.pg_timeout = args.db_timeout -- connect + send + read + conf.pg_timeout = args.db_timeout or conf.pg_timeout -- connect + send + read assert(prefix_handler.prepare_prefix(conf, args.nginx_conf, true)) diff --git a/kong/cmd/restart.lua b/kong/cmd/restart.lua index 0bc4777c47e9..4f9fcbede7bb 100644 --- a/kong/cmd/restart.lua +++ b/kong/cmd/restart.lua @@ -47,7 +47,7 @@ Options: -p,--prefix (optional string) prefix at which Kong should be running --nginx-conf (optional string) custom Nginx configuration template --run-migrations (optional boolean) optionally run migrations on the DB - --db-timeout (default 60) + --db-timeout (optional number) --lock-timeout (default 60) --nginx-conf-flags (optional string) flags that can be used to control how Nginx configuration templates are rendered diff --git a/kong/cmd/start.lua b/kong/cmd/start.lua index 63404cbaa98f..75c0c7b0af8a 100644 --- a/kong/cmd/start.lua +++ b/kong/cmd/start.lua @@ -44,14 +44,14 @@ local function cleanup_dangling_unix_sockets(prefix) end local function execute(args) - args.db_timeout = args.db_timeout * 1000 + args.db_timeout = args.db_timeout and (args.db_timeout * 1000) or nil args.lock_timeout = args.lock_timeout local conf = assert(conf_loader(args.conf, { prefix = args.prefix }, { starting = true })) - conf.pg_timeout = args.db_timeout -- connect + send + read + conf.pg_timeout = args.db_timeout or conf.pg_timeout -- connect + send + read assert(not kill.is_running(conf.nginx_pid), "Kong is already running in " .. conf.prefix) @@ -126,7 +126,7 @@ Options: --run-migrations (optional boolean) Run migrations before starting. - --db-timeout (default 60) Timeout, in seconds, for all database + --db-timeout (optional number) Timeout, in seconds, for all database operations. --lock-timeout (default 60) When --run-migrations is enabled, timeout,