Skip to content

Commit c19b6cc

Browse files
stop() now kills all created fibers
1 parent 3799fef commit c19b6cc

2 files changed

Lines changed: 7 additions & 28 deletions

File tree

metrics/plugins/graphite.lua

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

95-
-- for _, v in ipairs(GRAPHITE_FIBERS) do
96-
-- if v.name == graphite_fiber.name then
97-
-- error('failed to start fiber: ' .. graphite_fiber.name .. ", already exist")
98-
-- end
99-
-- end
10095
for name in pairs(GRAPHITE_FIBERS) do
10196
if name == graphite_fiber.name then
10297
error('failed to start fiber: ' .. graphite_fiber.name .. ", already exist")
@@ -115,25 +110,13 @@ function graphite.init(opts)
115110
GRAPHITE_FIBERS[graphite_fiber.name] = graphite_fiber
116111
end
117112

118-
function graphite.stop(opts)
119-
checks {
120-
prefix = '?string',
121-
host = '?string',
122-
port = '?number',
123-
send_interval = '?number'
124-
}
125-
126-
local graphite_fiber = create_fiber_table(opts)
127-
113+
function graphite.stop()
114+
-- stop should kill all registered fibers due to
115+
-- "require('config'):reload()" could be called on instance.
128116
for name in pairs(GRAPHITE_FIBERS) do
129-
if name == graphite_fiber.name then
130-
fiber.kill(GRAPHITE_FIBERS[name].fiber)
131-
GRAPHITE_FIBERS[name] = nil
132-
return
133-
end
117+
fiber.kill(GRAPHITE_FIBERS[name].fiber)
134118
end
135-
136-
error("failed to stop fiber: " .. graphite_fiber.name .. ", doesn't exist")
119+
GRAPHITE_FIBERS = {}
137120
end
138121

139122
return graphite

test/plugins/graphite_test.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ g.test_graphite_stop_default_fibers = function(cg)
180180
graphite.init({})
181181
t.assert_equals(count_workers(), 1)
182182

183-
graphite.stop({})
183+
graphite.stop()
184184
fiber.yield()
185185
t.assert_equals(count_workers(), 0)
186186
end)
@@ -219,11 +219,7 @@ g.test_graphite_stop_custom_fiber = function(cg)
219219

220220
t.assert_equals(count_workers(), 2)
221221

222-
graphite.stop(opts)
223-
fiber.yield()
224-
t.assert_equals(count_workers(), 1)
225-
226-
graphite.stop(opts2)
222+
graphite.stop()
227223
fiber.yield()
228224
t.assert_equals(count_workers(), 0)
229225
end)

0 commit comments

Comments
 (0)