File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,25 @@ extension String {
20
20
/// access to the file but releases it soon after. Retry to save the file if this happens. This matches what a user
21
21
/// would do.
22
22
package func writeWithRetry( to url: URL ) async throws {
23
+ // Depending on the system, mtime resolution might not be perfectly accurate. Particularly containers appear to have
24
+ // imprecise mtimes.
25
+ // Wait a short time period before writing the new file to avoid situations like the following:
26
+ // - We index a source file and the unit receives a time stamp and wait for indexing to finish
27
+ // - We modify the source file but so quickly after the unit has been modified that the updated source file
28
+ // receives the same mtime as the unit file
29
+ // - We now assume that the we have an up-to-date index for this source file even though we do not.
30
+ //
31
+ // Waiting 10ms appears to be enough to avoid this situation on the systems we care about.
32
+ //
33
+ // Do determine the mtime accuracy on a system, run the following bash commands and look at the time gaps between
34
+ // the time stamps
35
+ // ```
36
+ // mkdir /tmp/dir
37
+ // for x in $(seq 1 1000); do touch /tmp/dir/$x; done
38
+ // for x in /tmp/dir/*; do stat $x; done | grep Modify | sort | uniq
39
+ // ```
40
+ try await Task . sleep ( for: . milliseconds( 10 ) )
41
+
23
42
#if os(Windows)
24
43
try await repeatUntilExpectedResult ( timeout: . seconds( 10 ) , sleepInterval: . milliseconds( 200 ) ) {
25
44
do {
You can’t perform that action at this time.
0 commit comments