Skip to content

Commit fc0c2a1

Browse files
committed
rabbit_feature_flags: Wait for old registry to be purged
... before deleting it and load the new code. In some rare cases, the soft purge didn't work because another process was running the old code. Thus the delete would fail. Now, we wait for the soft purge to succeed before proceeding. (cherry picked from commit 2bd7132)
1 parent fca7492 commit fc0c2a1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/rabbit_feature_flags.erl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,8 @@ load_registry_mod(Mod, Bin) ->
12321232
%% Time to load the new registry, replacing the old one. We use a
12331233
%% lock here to synchronize concurrent reloads.
12341234
global:set_lock(?FF_REGISTRY_LOADING_LOCK, [node()]),
1235-
_ = code:soft_purge(Mod),
1236-
_ = code:delete(Mod),
1235+
ok = purge_old_registry(Mod),
1236+
true = code:delete(Mod),
12371237
Ret = code:load_binary(Mod, FakeFilename, Bin),
12381238
global:del_lock(?FF_REGISTRY_LOADING_LOCK, [node()]),
12391239
case Ret of
@@ -1246,6 +1246,18 @@ load_registry_mod(Mod, Bin) ->
12461246
throw({feature_flag_registry_reload_failure, Reason})
12471247
end.
12481248

1249+
purge_old_registry(Mod) ->
1250+
case code:is_loaded(Mod) of
1251+
{file, _} -> do_purge_old_registry(Mod);
1252+
false -> ok
1253+
end.
1254+
1255+
do_purge_old_registry(Mod) ->
1256+
case code:soft_purge(Mod) of
1257+
true -> ok;
1258+
false -> do_purge_old_registry(Mod)
1259+
end.
1260+
12491261
%% -------------------------------------------------------------------
12501262
%% Feature flags state storage.
12511263
%% -------------------------------------------------------------------

0 commit comments

Comments
 (0)