fix: init dns resolvers in stream subsystem (#4186)

This commit is contained in:
Alex Zhang 2021-05-06 16:54:11 +08:00 committed by GitHub
parent 17ae333df4
commit f7460eeee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 3 deletions

View File

@ -85,7 +85,11 @@ stream {
init_by_lua_block {
require "resty.core"
apisix = require("apisix")
apisix.stream_init()
local dns_resolver = { {% for _, dns_addr in ipairs(dns_resolver or {}) do %} "{*dns_addr*}", {% end %} }
local args = {
dns_resolver = dns_resolver,
}
apisix.stream_init(args)
}
init_worker_by_lua_block {

View File

@ -715,9 +715,11 @@ function _M.http_control()
end
function _M.stream_init()
function _M.stream_init(args)
core.log.info("enter stream_init")
core.resolver.init_resolver(args)
if core.config.init then
local ok, err = core.config.init()
if not ok then

View File

@ -263,7 +263,10 @@ _EOC_
require "resty.core"
apisix = require("apisix")
apisix.stream_init()
local args = {
dns_resolver = $dns_addrs_tbl_str,
}
apisix.stream_init(args)
_EOC_
$stream_config .= <<_EOC_;

33
t/misc/patch.t vendored
View File

@ -151,3 +151,36 @@ apisix:
GET /t
--- response_body
301
=== TEST 5: resolve host by ourselves (in stream sub-system)
--- yaml_config
apisix:
node_listen: 1984
enable_resolv_search_opt: true
--- stream_enable
--- stream_server_config
content_by_lua_block {
local sock = ngx.req.socket(true)
-- drain the buffer
local _, err = sock:receive(1)
if err ~= nil then
ngx.log(ngx.ERR, err)
return ngx.exit(-1)
end
local http = require("resty.http")
local httpc = http.new()
local res, err = httpc:request_uri("http://apisix")
if not res then
ngx.log(ngx.ERR, err)
return ngx.exit(-1)
end
sock:send(res.status)
}
--- stream_request eval
m
--- stream_response: 301
--- no_error_log
[error]