Skip to content

Commit e51e070

Browse files
authored
Merge pull request #553 from rabbitmq/fix-rare-fd-leak-in-follower
Fix rare fd leaks in follower.
2 parents 2b8035c + 66de28e commit e51e070

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/ra_server.erl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,8 @@ handle_follower(#append_entries_rpc{term = Term,
12361236
" including ~b entries did not validate local log. "
12371237
"Local last index ~b",
12381238
[LogId, PLIdx, length(Entries0), LocalLastIdx]),
1239-
{LVTerm, State} = fetch_term(LastValidatedIdx, State0),
1239+
{LVTerm, State} = fetch_term(LastValidatedIdx,
1240+
State0#{log => Log2}),
12401241
Reply = #append_entries_reply{term = CurTerm,
12411242
success = true,
12421243
next_index = LastValidatedIdx + 1,
@@ -1286,7 +1287,8 @@ handle_follower(#append_entries_rpc{term = Term,
12861287
transition_to => follower}}},
12871288
Effects};
12881289
{term_mismatch, OtherTerm, Log0} ->
1289-
LastApplied = maps:get(last_applied, State00),
1290+
State1 = State0#{log => Log0},
1291+
LastApplied = maps:get(last_applied, State1),
12901292
?INFO("~ts: term mismatch - follower had entry at ~b with term ~b "
12911293
"but not with term ~b. "
12921294
"Asking leader ~w to resend from ~b",
@@ -1301,11 +1303,10 @@ handle_follower(#append_entries_rpc{term = Term,
13011303
% This _may_ overwrite some valid entries but is probably the
13021304
% simplest and most reliable way to proceed
13031305
{Reply, State} = mismatch_append_entries_reply(Term, LastApplied,
1304-
State0),
1306+
State1),
13051307
Effects = [cast_reply(Id, LeaderId, Reply) | Effects0],
13061308
{await_condition,
1307-
State#{log => Log0,
1308-
condition =>
1309+
State#{condition =>
13091310
#{predicate_fun => follower_catchup_cond_fun(term_mismatch),
13101311
% repeat reply effect on condition timeout
13111312
timeout => #{effects => Effects,

0 commit comments

Comments
 (0)