Commit 7ad4c9a0 authored by Marek Vavruša's avatar Marek Vavruša

daemon: fixed race condition when canceling one event multiple times

parent f8636079
......@@ -495,7 +495,9 @@ static void event_callback(uv_timer_t *timer)
int ret = execute_callback(L, 1);
/* Free callback if not recurrent or an error */
if (ret != 0 || uv_timer_get_repeat(timer) == 0) {
uv_close((uv_handle_t *)timer, (uv_close_cb) event_free);
if (!uv_is_closing((uv_handle_t *)timer)) {
uv_close((uv_handle_t *)timer, (uv_close_cb) event_free);
}
}
}
......@@ -572,7 +574,9 @@ static int event_cancel(lua_State *L)
/* Close the timer */
lua_rawgeti(L, -1, 2);
uv_handle_t *timer = lua_touserdata(L, -1);
uv_close(timer, (uv_close_cb) event_free);
if (!uv_is_closing(timer)) {
uv_close(timer, (uv_close_cb) event_free);
}
lua_pushboolean(L, true);
return 1;
}
......
......@@ -89,7 +89,6 @@ end
-- Plan refresh event and re-schedule itself based on the result of the callback
local function refresh_plan(trust_anchors, timeout, refresh_cb)
if trust_anchors.refresh_ev ~= nil then event.cancel(trust_anchors.refresh_ev) end
trust_anchors.refresh_ev = event.after(timeout, function (ev)
resolve('.', kres.type.DNSKEY, kres.class.IN, kres.query.NO_CACHE,
function (pkt)
......@@ -198,6 +197,7 @@ local trust_anchors = {
if is_unmanaged then trust_anchors.file_current = nil end
trust_anchors.keyset = {}
if trust_anchors.update(new_keys, true) then
if trust_anchors.refresh_ev ~= nil then event.cancel(trust_anchors.refresh_ev) end
refresh_plan(trust_anchors, sec, active_refresh)
end
end,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment