Skip to content

Commit

Permalink
fix(balancer) delay initialization of balancer objects
Browse files Browse the repository at this point in the history
When upstreams include targets using hostnames instead of IPs, the
initialization of balancer objects needs to perform DNS resolution, which
involves opening a socket, which is not available in the init_worker phase.

This patch delays balancer initialization to the access phase.
  • Loading branch information
hishamhm committed Jan 29, 2018
1 parent de6390e commit b4efc00
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions kong/core/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ local unpack = unpack

local router, router_err, router_version
local server_header = _KONG._NAME.."/".._KONG._VERSION
local balancer_initialized = false


local function get_now()
Expand Down Expand Up @@ -85,12 +86,6 @@ return {
local cluster_events = singletons.cluster_events


-- initialize balancers


balancer.init()


-- events dispatcher


Expand Down Expand Up @@ -320,6 +315,14 @@ return {
},
access = {
before = function(ctx)

-- ensure upstreams are initialized

if not balancer_initialized then
balancer.init()
balancer_initialized = true
end

-- ensure router is up-to-date

local version, err = singletons.cache:get("router:version", {
Expand Down

0 comments on commit b4efc00

Please sign in to comment.