-
Notifications
You must be signed in to change notification settings - Fork 0
fix: prevent data races in MemFs Rename and RemoveAll #3
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
base: master
Are you sure you want to change the base?
Conversation
ed7f3f2 to
283a094
Compare
|
|
||
| m.registerWithParent(file, 0) | ||
| m.mu.Unlock() | ||
| m.getData()[name] = file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review: Drive-by change in preparation of potential future removal of implicit MkdirAll behavior of registerWithParent.
The ordering is more explicit and avoids inconsistent state if an error path is introduced.
Rename: If unRegisterWithParent or renameDescendants returns an error, the function returns while holding an exclusive write lock, but the deferred RUnlock runs instead of Unlock. RemoveAll: Unsafe modification of data map under the assumption that all entries belong to unregistered path. This implementaiton also raced with non-standard implicit MkdirAll behavior of Create.
283a094 to
0f8fdbe
Compare
| m.registerWithParent(item, perm) | ||
| m.mu.Unlock() | ||
|
|
||
| return m.setFileMode(name, perm|os.ModeDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review: Dupe, mem.SetMode is already used above.
| m.mu.Lock() | ||
| mem.SetModTime(f, mtime) | ||
| m.mu.Unlock() | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Motivation: Consistency. We already have a reference to the file handle, and mem functions acquire f.Lock. Whether or not we're updating a stale file is irrelevant.
Rename: If unRegisterWithParent or renameDescendants returns an error,
the function returns while holding an exclusive write lock, but the
deferred RUnlock runs instead of Unlock.
RemoveAll: Unsafe modification of data map under the assumption that all
entries belong to unregistered path. This implementaiton also raced with
non-standard implicit MkdirAll behavior of Create.