Skip to content

Debug io regression#2303

Draft
ValentaTomas wants to merge 2 commits intomainfrom
debug-io-err
Draft

Debug io regression#2303
ValentaTomas wants to merge 2 commits intomainfrom
debug-io-err

Conversation

@ValentaTomas
Copy link
Copy Markdown
Member

No description provided.

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 3, 2026

PR Summary

Low Risk
Low risk change that only reorders validation to fail fast for oversized cache allocations, avoiding creating/truncating an invalidly large file before mmap.

Overview
Fixes an IO regression in block.NewCache by validating size against math.MaxInt before truncating the backing file, so oversized cache requests fail fast without attempting to allocate/truncate a huge sparse file prior to mmap mapping.

Written by Cursor Bugbot for commit c1636a4. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

}

mm, err := mmap.MapRegion(f, int(size), mmap.RDWR, 0, 0)
mm, err := mmap.MapRegion(f, int(size), unix.PROT_READ|unix.PROT_WRITE, 0, 0)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: raw unix PROT flags conflict with mmap-go own flag encoding, silently switching MAP_SHARED to MAP_PRIVATE.

mmap-go defines its own constants (not POSIX PROT_* values):

  • mmap.RDONLY = 0
  • mmap.RDWR = 1
  • mmap.COPY = 2 (triggers MAP_PRIVATE)
  • mmap.EXEC = 4

unix.PROT_READ|unix.PROT_WRITE = 0x1|0x2 = 3, which mmap-go interprets as RDWR|COPY (1|2=3). In mmap_unix.go the COPY branch fires first in the switch:

case inprot&COPY != 0:  // 3 & 2 = 2, non-zero -> TRUE
    prot |= syscall.PROT_WRITE
    flags = syscall.MAP_PRIVATE  // writes never reach the file

With MAP_PRIVATE, all writes to the mmap stay in process memory and are never flushed to the backing file. This breaks ExportToDiff which reads dirty blocks from the file via unix.CopyFileRange/unix.SyncFileRange -- those reads will see stale/zero data.

The original mmap.RDWR (= 1) correctly produced MAP_SHARED. This line should be reverted to mmap.RDWR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants