Skip to content

Commit 191fd2b

Browse files
kjnilssonmergify[bot]
authored andcommitted
Fix fd leak in rabbit_fifo
The handle_aux clause for `oldest_entry_timestamp` did not return the updated Log structure and thus ends up leaking file descriptors when this function is called and the segment isn't already open. (cherry picked from commit 14da3a1) (cherry picked from commit d0800d8)
1 parent f384947 commit 191fd2b

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

deps/rabbit/src/rabbit_fifo.erl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,18 +1102,19 @@ handle_aux(_RaState, cast, eol, #?AUX{name = Name} = Aux, Log, _) ->
11021102
ets:delete(rabbit_fifo_usage, Name),
11031103
{no_reply, Aux, Log};
11041104
handle_aux(_RaState, {call, _From}, oldest_entry_timestamp, Aux,
1105-
Log, #?MODULE{} = State) ->
1106-
Ts = case smallest_raft_index(State) of
1107-
%% if there are no entries, we return current timestamp
1108-
%% so that any previously obtained entries are considered older than this
1109-
undefined ->
1110-
erlang:system_time(millisecond);
1111-
Idx when is_integer(Idx) ->
1112-
%% TODO: make more defensive to avoid potential crash
1113-
{{_, _, {_, Meta, _, _}}, _Log1} = ra_log:fetch(Idx, Log),
1114-
#{ts := Timestamp} = Meta,
1115-
Timestamp
1116-
end,
1105+
Log0, #?MODULE{} = State) ->
1106+
{Ts, Log} = case smallest_raft_index(State) of
1107+
%% if there are no entries, we return current timestamp
1108+
%% so that any previously obtained entries are considered
1109+
%% older than this
1110+
undefined ->
1111+
{erlang:system_time(millisecond), Log0};
1112+
Idx when is_integer(Idx) ->
1113+
%% TODO: make more defensive to avoid potential crash
1114+
{{_, _, {_, Meta, _, _}}, Log1} = ra_log:fetch(Idx, Log0),
1115+
#{ts := Timestamp} = Meta,
1116+
{Timestamp, Log1}
1117+
end,
11171118
{reply, {ok, Ts}, Aux, Log};
11181119
handle_aux(_RaState, {call, _From}, {peek, Pos}, Aux0,
11191120
Log0, MacState) ->

0 commit comments

Comments
 (0)