Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/exp/mmap: mapping 0 length file is already closed #56261

Closed
robaho opened this issue Oct 16, 2022 · 5 comments
Closed

x/exp/mmap: mapping 0 length file is already closed #56261

robaho opened this issue Oct 16, 2022 · 5 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@robaho
Copy link

robaho commented Oct 16, 2022

go version go1.19.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
amd64, intel i7

If you use mmap to map a file of 0 length, any future usage of the mapped file results in an error mmap: closed

The offending code is:

	size := fi.Size()
	if size == 0 {
		return &ReaderAt{}, nil
	}

in mmap_unix.go, in func Open(filename string) (*ReaderAt, error) - lines 92-95.

I don't think this is correct or expected behavior. You should be able to mmap a zero length file and use it.

@dr2chase
Copy link
Contributor

Simple as this is, a reproducer would still be nice.

@robaho
Copy link
Author

robaho commented Oct 17, 2022

I will add one this evening.

@robaho
Copy link
Author

robaho commented Oct 17, 2022

Attaching test case. Notice that 0 length file returns 'closed', while a non-zero file returns the expected EOF.
mmap_test.go.txt

@ianlancetaylor ianlancetaylor changed the title mmap: mapping 0 length file is already closed x/exp/mmap: mapping 0 length file is already closed Oct 17, 2022
@gopherbot gopherbot added this to the Unreleased milestone Oct 17, 2022
@ianlancetaylor
Copy link
Contributor

CC @nigeltao who originally wrote x/exp/mmap.

@ianlancetaylor ianlancetaylor added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 17, 2022
@gopherbot
Copy link

Change https://go.dev/cl/443576 mentions this issue: mmap: allow mapping a zero-sized file

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 18, 2022
udzura added a commit to udzura/bitcaskdb that referenced this issue Apr 17, 2023
Better handling for opening 0 sized file.
ref: golang/go#56261
@golang golang locked and limited conversation to collaborators Oct 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants