diff --git a/lib/api.js b/lib/api.js index c0e570095..bccf917f8 100644 --- a/lib/api.js +++ b/lib/api.js @@ -190,6 +190,9 @@ nThen(function (w) { removed++; } }); + if (Env.store) { + Env.store.closeInactiveChannels(active); + } if (removed) { Env.Log.info("CLEANED_ACTIVE_CHANNELS_MAP", {removed}); } diff --git a/lib/hk-util.js b/lib/hk-util.js index 7080d3d4a..1bc7f2022 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -146,6 +146,7 @@ const dropChannel = HK.dropChannel = function (Env, chanName) { expireChannel(Env, chanName); }, TEMPORARY_CHANNEL_LIFETIME); } + store.closeChannel(chanName, function () {}); }; /* checkExpired diff --git a/lib/storage/file.js b/lib/storage/file.js index 2c2888f7a..98cbfd7db 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -286,6 +286,16 @@ var closeChannel = function (env, channelName, cb) { } }; +var closeInactiveChannels = function (env, schedule, active) { + Object.keys(env.channels).forEach(channelName => { + if (!active.includes(channelName)) { + schedule.ordered(channelName, function (next) { + closeChannel(env, channelName, next); + }); + } + }); +}; + var clearOffset = function (env, channelId, cb) { var path = mkOffsetPath(env, channelId); // we should always be able to recover from invalid offsets, so failure to delete them @@ -1445,6 +1455,9 @@ module.exports.create = function (conf, _cb) { closeChannel(env, channelName, Util.both(cb, next)); }); }, + closeInactiveChannels: function (active) { + closeInactiveChannels(env, schedule, active); + }, // write to a log file log: function (channelName, content, cb) { // you probably want the events in your log to be in the correct order.