diff --git a/changelog/unreleased/kong/fix-core-pass-ctx-to-log-init-worker-errors.yml b/changelog/unreleased/kong/fix-core-pass-ctx-to-log-init-worker-errors.yml new file mode 100644 index 000000000000..b702d658b44a --- /dev/null +++ b/changelog/unreleased/kong/fix-core-pass-ctx-to-log-init-worker-errors.yml @@ -0,0 +1,4 @@ +message: | + Fix to always pass `ngx.ctx` to `log_init_worker_errors` as otherwise it may runtime crash. +type: bugfix +scope: Core diff --git a/kong/init.lua b/kong/init.lua index 70abad8b59c0..584cca12c254 100644 --- a/kong/init.lua +++ b/kong/init.lua @@ -1952,10 +1952,12 @@ end Kong.status_header_filter = Kong.admin_header_filter -function Kong.serve_cluster_listener(options) - log_init_worker_errors() +function Kong.serve_cluster_listener() + local ctx = ngx.ctx + + log_init_worker_errors(ctx) - ngx.ctx.KONG_PHASE = PHASES.cluster_listener + ctx.KONG_PHASE = PHASES.cluster_listener return kong.clustering:handle_cp_websocket() end @@ -1966,10 +1968,12 @@ function Kong.stream_api() end -function Kong.serve_cluster_rpc_listener(options) - log_init_worker_errors() +function Kong.serve_cluster_rpc_listener() + local ctx = ngx.ctx + + log_init_worker_errors(ctx) - ngx.ctx.KONG_PHASE = PHASES.cluster_listener + ctx.KONG_PHASE = PHASES.cluster_listener return kong.rpc:handle_websocket() end