Skip to content

Commit 14da3a1

Browse files
committed
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.
1 parent 9950188 commit 14da3a1

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

0 commit comments

Comments
 (0)