Skip to content

Commit 2ede9e4

Browse files
committed
Fix rare fd leaks in follower.
In the case where an append entries rpc is received that does not also validate the log it was possible to leak file handles if the check of the previous index required a read from a disk segment. Also fix a potential leak with mismatched terms
1 parent 2b8035c commit 2ede9e4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/ra_server.erl

Lines changed: 4 additions & 4 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,
@@ -1301,11 +1302,10 @@ handle_follower(#append_entries_rpc{term = Term,
13011302
% This _may_ overwrite some valid entries but is probably the
13021303
% simplest and most reliable way to proceed
13031304
{Reply, State} = mismatch_append_entries_reply(Term, LastApplied,
1304-
State0),
1305+
State0#{log => Log0}),
13051306
Effects = [cast_reply(Id, LeaderId, Reply) | Effects0],
13061307
{await_condition,
1307-
State#{log => Log0,
1308-
condition =>
1308+
State#{condition =>
13091309
#{predicate_fun => follower_catchup_cond_fun(term_mismatch),
13101310
% repeat reply effect on condition timeout
13111311
timeout => #{effects => Effects,

0 commit comments

Comments
 (0)