Skip to content

Commit 09a0bad

Browse files
graphite: init() kills previous fiber if exist
1 parent ce27ae1 commit 09a0bad

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

metrics/plugins/graphite.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,14 @@ function graphite.init(opts)
9292
local sock = socket('AF_INET', 'SOCK_DGRAM', 'udp')
9393
assert(sock ~= nil, 'Socket creation failed')
9494

95+
-- require('config'):reload() triggers calling only validate() and apply()
96+
-- role's methods without stop().
97+
-- so, we should kill previous fiber if exist.
9598
for name in pairs(GRAPHITE_FIBERS) do
9699
if name == graphite_fiber.name then
97-
error('failed to start fiber: ' .. graphite_fiber.name .. ", already exist")
100+
fiber.kill(GRAPHITE_FIBERS[name].fiber)
101+
GRAPHITE_FIBERS[name] = nil
102+
require('fiber').yield()
98103
end
99104
end
100105

test/plugins/graphite_test.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,30 @@ g.test_graphite_stop_custom_fiber = function(cg)
221221
t.assert_equals(count_workers(), 0)
222222
end)
223223
end
224+
225+
g.test_graphite_double_start = function(cg)
226+
cg.server:exec(function()
227+
local fiber = require('fiber')
228+
local fun = require('fun')
229+
local graphite = require('metrics.plugins.graphite')
230+
231+
local function count_workers()
232+
return fun.iter(fiber.info()):
233+
filter(function(_, x) return string.find(x.name, 'metrics_graphite_worker') end):
234+
length()
235+
end
236+
237+
t.assert_equals(count_workers(), 0)
238+
239+
graphite.init({})
240+
241+
t.assert_equals(count_workers(), 1)
242+
243+
graphite.init({})
244+
245+
t.assert_equals(count_workers(), 1)
246+
247+
graphite.stop()
248+
t.assert_equals(count_workers(), 0)
249+
end)
250+
end

0 commit comments

Comments
 (0)