Skip to content

fix: return os.ErrClosed on double Close() in MemMapFs#588

Open
Yanhu007 wants to merge 1 commit intospf13:masterfrom
Yanhu007:fix/memmap-double-close-error
Open

fix: return os.ErrClosed on double Close() in MemMapFs#588
Yanhu007 wants to merge 1 commit intospf13:masterfrom
Yanhu007:fix/memmap-double-close-error

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #567

Problem

mem.File.Close() silently succeeds when called multiple times, while os.File.Close() returns an error (os.ErrClosed). This inconsistency causes bugs to go undetected in tests using MemMapFs that only surface in production with OsFs.

Fix

Check the closed flag under the lock before proceeding. If already closed, return os.ErrClosed to match os.File behavior.

Testing

All existing tests pass.

MemMapFs File.Close() silently succeeds when called multiple times,
while OsFs returns an error. This inconsistency causes bugs to go
undetected in tests using MemMapFs that only surface in production
with OsFs.

Return os.ErrClosed when the file is already closed, matching the
behavior of os.File.

Fixes spf13#567
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

MemMapFS Does not Error on Double Close

2 participants