Skip to content

osiris_log: Fix infinite recursion with segment size smaller than header#217

Draft
the-mikedavis wants to merge 1 commit into
mainfrom
md/max-seg
Draft

osiris_log: Fix infinite recursion with segment size smaller than header#217
the-mikedavis wants to merge 1 commit into
mainfrom
md/max-seg

Conversation

@the-mikedavis
Copy link
Copy Markdown
Collaborator

@the-mikedavis the-mikedavis commented May 16, 2026

The minimum size of any segment is always the header size (8 bytes, MAGIC plus 32 bit version). When setting the segment size bytes to a single byte, the transition to the second segment would always recurse indefinitely because transitioning to the next segment could never succeed. This change bails out and allows a 1-byte max segment size to mean a single chunk per segment.

This is a total edge-case and not probably worth worrying about, but this is possible because the header x-stream-max-segment-size-bytes does not check against a minimum. It is only checked to be non-negative and under a maximum.

The minimum size of any segment is always the header size (8 bytes,
MAGIC plus 32 bit version). When setting the segment size bytes to a
single byte, the transition to the second segment would always recurse
indefinitely because transitioning to the next segment could never
succeed. This change bails out and allows a 1-byte max segment size to
mean a single chunk per segment.
@the-mikedavis the-mikedavis requested a review from kjnilsson May 16, 2026 20:57
@the-mikedavis the-mikedavis self-assigned this May 16, 2026
@the-mikedavis the-mikedavis added the bug Something isn't working label May 16, 2026
@kjnilsson kjnilsson requested a review from Copilot May 29, 2026 09:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an infinite recursion in osiris_log:write_chunk/6 that occurred when max_segment_size_bytes was set to a value smaller than or equal to the segment file header size (8 bytes). Because a freshly opened segment already accounts for ?LOG_HEADER_SIZE bytes, max_segment_size_reached/1 would always return true, causing write_chunkopen_new_segmentwrite_chunk to loop forever.

Changes:

  • Guard the byte-based segment-roll predicate with MaxSizeBytes > ?LOG_HEADER_SIZE, effectively disabling bytes-based rolling for tiny limits.
  • Add a regression test that writes two chunks with max_segment_size_bytes => 1.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/osiris_log.erl Skip byte-size segment roll when MaxSizeBytes is at or below the segment header size, preventing infinite recursion.
test/osiris_log_SUITE.erl New write_with_small_max_segment_size test case covering the edge case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kjnilsson
Copy link
Copy Markdown
Contributor

How does this fix interact with tracking snapshots whcih are written by the log itself? Really we should accept a tracking snapshot + 1 user chunk for every stream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants