Skip to content

Commit e1b2223

Browse files
committed
Handle empty index array in recover_fragments/7
When a stream is created but no segment has been flushed yet, the index file exists on disk but contains no records after the header. The call to `rabbitmq_stream_s3_array:at/3` on an empty binary crashes with `badarg`. Add a guard clause matching `<<>>` that returns a default empty fragment, consistent with the `[]` branch in `init_manifest/2`.
1 parent 846762c commit e1b2223

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/rabbitmq_stream_s3_log_manifest.erl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ recover_fragments(IdxFile, Acc) ->
226226
IdxArray
227227
).
228228

229+
recover_fragments(
230+
_Threshold0,
231+
_SegmentFile,
232+
SegmentOffset,
233+
SeqNo0,
234+
_NumChunks0,
235+
Fragments0,
236+
<<>>
237+
) ->
238+
%% The index file exists but contains no records yet (e.g. the stream was
239+
%% created but no segment has been flushed). Treat as an empty fragment.
240+
{#fragment{segment_offset = SegmentOffset, seq_no = SeqNo0}, Fragments0};
229241
recover_fragments(
230242
Threshold0,
231243
SegmentFile,

0 commit comments

Comments
 (0)