Skip to content

Commit 51d4c7b

Browse files
ita-sammannsergos
authored andcommitted
roles: fix redunant server recreation
Changing the address during a configuration reload resulted in incorrect assertions, which always recreated the server. After this patch server will recreate itself only in changing a listen parameter. Closes #219
1 parent a932a68 commit 51d4c7b

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212

1313
## Fixed
1414

15+
- Do not recreate server if it's address and port were not changed (#219).
16+
1517
## [1.8.0] - 2025-07-07
1618

1719
The release introduces a new log level configuration option in `httpd` role

roles/httpd.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ local function apply_http(name, node)
121121
httpd = httpd,
122122
routes = {},
123123
}
124-
elseif servers[name].host ~= host or servers[name].port ~= port then
124+
elseif servers[name].httpd.host ~= host or servers[name].httpd.port ~= port then
125125
servers[name].httpd:stop()
126126
servers[name].httpd = http_server.new(host, port, parse_params(node))
127127
servers[name].httpd:start()

test/integration/httpd_role_test.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,22 @@ g.test_change_server_addr_on_the_run = function(cg)
172172
t.assert_equals(resp.body, 'pong')
173173
end
174174

175+
g.test_keep_existing_server_routes_on_config_reload = function(cg)
176+
local resp = http_client:get('http://0.0.0.0:13001/ping_once')
177+
t.assert_equals(resp.status, 200, 'response not 200')
178+
t.assert_equals(resp.body, 'pong once')
179+
180+
local cfg = table.deepcopy(config)
181+
cfg.credentials.users.testguest = { roles = {'super'} }
182+
treegen.write_file(cg.server.chdir, 'config.yaml', yaml.encode(cfg))
183+
local _, err = cg.server:eval("require('config'):reload()")
184+
t.assert_not(err)
185+
186+
resp = http_client:get('http://0.0.0.0:13001/ping_once')
187+
t.assert_equals(resp.status, 200, 'response not 200')
188+
t.assert_equals(resp.body, 'pong once')
189+
end
190+
175191
g.test_log_requests = function(cg)
176192
t.skip_if(cg.params.use_tls)
177193

test/mocks/mock_role.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local M = {dependencies = { 'roles.httpd' }}
22

33
local servers = {}
4+
local applied = {}
45

56
M.validate = function() end
67

@@ -14,6 +15,15 @@ M.apply = function(conf)
1415
}, function(tx)
1516
return tx:render({text = 'pong'})
1617
end)
18+
19+
if applied[server.id] == nil then
20+
servers[server.id]:route({
21+
path = '/ping_once',
22+
}, function(tx)
23+
return tx:render({text = 'pong once'})
24+
end)
25+
applied[server.id] = {}
26+
end
1727
end
1828
end
1929
end

0 commit comments

Comments
 (0)