Software /
code /
prosody
Changeset
8657:a804f2e75f10
MUC: Prevent room eviction on storage failure
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 07 Mar 2018 17:38:01 +0100 |
parents | 8656:0e84814a7ece |
children | 8658:75c7e887c4b9 |
files | plugins/muc/mod_muc.lua |
diffstat | 1 files changed, 15 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/muc/mod_muc.lua Mon Mar 12 21:47:39 2018 +0100 +++ b/plugins/muc/mod_muc.lua Wed Mar 07 17:38:01 2018 +0100 @@ -129,7 +129,11 @@ module:log("debug", "Evicting room %s", jid); eviction_hit_rate(); room_items_cache[room.jid] = room:get_public() and room:get_name() or nil; - room_save(room, nil, true); -- Force to disk + local ok, err = room_save(room, nil, true); -- Force to disk + if not ok then + module:log("error", "Failed to swap inactive room %s to disk: %s", jid, err); + return false; + end end); -- Automatically destroy empty non-persistent rooms @@ -141,9 +145,12 @@ end, -1); function track_room(room) - rooms:set(room.jid, room); - -- When room is created, over-ride 'save' method - room.save = room_save; + if rooms:set(room.jid, room) then + -- When room is created, over-ride 'save' method + room.save = room_save; + return room; + end + return false; end local function restore_room(jid) @@ -153,8 +160,7 @@ if data then module:log("debug", "Restoring room %s from storage", jid); local room = muclib.restore_room(data, state); - track_room(room); - return room; + return track_room(room); elseif err then module:log("error", "Error restoring room %s from storage: %s", jid, err); local room = muclib.new_room(jid, { locked = math.huge }); @@ -216,10 +222,10 @@ for room_jid in pairs(persistent_rooms_storage:get(nil) or {}) do if not seen[room_jid] then local room = restore_room(room_jid); - if room == nil then + if room then + coroutine.yield(room); + else module:log("error", "Missing data for room '%s', omitting from iteration", room_jid); - else - coroutine.yield(room); end end end