Patchwork D11781: dirstate: add a comment about a racy piece of code during updates

login
register
mail settings
Submitter phabricator
Date Nov. 24, 2021, 11:12 a.m.
Message ID <differential-rev-PHID-DREV-edsa5jp3umkyylljwibe-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50107/
State New
Headers show

Comments

phabricator - Nov. 24, 2021, 11:12 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is a bits that is not really correct but works "fine" in practice. Lets
  write it down so that people stop wondering how that logic might be correct.
  It is not.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11781

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1404,6 +1404,31 @@ 
                 atomictemp=atomictemp,
             )
             if wantfiledata:
+                # XXX note that there is a race windows between the time we
+                # write the clean data into the file and we stats it. So a
+                # writting process meddling with the file content right as we
+                # writes it could cause bad data to be gathered.
+                #
+                # They are 2 data we gather here
+                # - the mode:
+                #       That we actually just wrote, we should not need to read
+                #       it from disk, (except not all mode might have survived
+                #       the disk round-trip, which is another issue)
+                # - the mtime,
+                #       That could be accurate enough on filesystem with
+                #       nanosecond precision, but is read in a racy way.
+                #
+                # (note: we get the size from the data we write, which is sane)
+                #
+                # So in theory the data returned here are fully racy, but in
+                # practice "it works mostly fine".
+                #
+                # Do not be surprised if you end up reading this while
+                # looking for the source of some buggy status. Feel free to
+                # improve this in the future, but we cannot simply stop
+                # gathering information otherwise `hg status` call made after a
+                # large `hg update` runs would have to redo a similar amount of
+                # work to restore and compare all files content.
                 s = wfctx.lstat()
                 mode = s.st_mode
                 mtime = timestamp.mtime_of(s)