Skip to content

Comments

fix datarace on updatetime#1003

Merged
pfitzseb merged 2 commits intomasterfrom
jn/updatetime-datarace
Feb 16, 2026
Merged

fix datarace on updatetime#1003
pfitzseb merged 2 commits intomasterfrom
jn/updatetime-datarace

Conversation

@vtjnash
Copy link
Collaborator

@vtjnash vtjnash commented Jan 30, 2026

There was a TOCTOU inversion here causing this to be a datarace. The time needs to be looked up in advance of looking at any mtime.

There was a TOCTOU inversion here causing this to be a datarace. The
time needs to be looked up in advance of looking at any mtime.
stillwatching = haskey(watched_files, dirname)
if stillwatching
wf = watched_files[dirname]
timestamp = updatetime!(wf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doing this unconditionally (and/or this early) seems to break the test added in #342.

Seems like this should maybe just be timestamp = wf.timestamp, keeping the original line 337 intact.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doing this conditionally in any form is a TOCTOU data race and unsound

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay, I see what the test wants to do though, and what the test wants is not what this function is currently capable of doing. The only way to make that test pass reliably is to track changes to the mtime+inode+size triple on a individual file bases, and not use updatetime at all

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to use ctime instead, so that any metadata change since the last scan (such as a rename) will also trigger a full re-inspection of the contents

@pfitzseb pfitzseb merged commit 87539be into master Feb 16, 2026
22 of 24 checks passed
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