Skip to content
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

FileWatch triggers file changed even if only file attributes changed #4706

Closed
wesleyfr opened this issue Jun 29, 2021 · 6 comments · Fixed by #4715
Closed

FileWatch triggers file changed even if only file attributes changed #4706

wesleyfr opened this issue Jun 29, 2021 · 6 comments · Fixed by #4715
Labels
bug Something isn't working Windows

Comments

@wesleyfr
Copy link

wesleyfr commented Jun 29, 2021

Hello,
I noticed FileWatch detects file change even if the file is accessed but untouched.
Thank you !

Expected Behavior

FileWatch should not detect a change if the file is unchanged.
According to the doc FileWatch should trigger only on create, modify, or delete : "SeenFiles is a list of paths which changed (create, modify, or delete)."

Current Behavior

FileWatch detects a change if the file is accessed.

> tilt get filewatches configs:singleton -o yaml
....
  - seenFiles:
    - C:\xxx\helm-values.tilt.yaml
    time: "2021-06-29T17:04:05.777668Z"
  lastEventTime: "2021-06-29T17:04:05.777668Z"
  monitorStartTime: "2021-06-29T14:08:54.952365Z"
> PS C:\xxx> Get-Item C:\xxx\helm-values.tilt.yaml | Select-Object LastAccessTimeUtc, LastWriteTimeUtc

LastAccessTimeUtc    LastWriteTimeUtc
-----------------    ----------------
6/29/2021 5:04:14 PM 5/14/2021 4:00:59 PM

(you can see that LastWriteTimeUtc does not match with the FileWatch lastEventTime, but LastAccessTimeUtc match)

Context

tilt doctor Output

$ tilt doctor
Tilt: v0.20.8, built 2021-06-18
System: windows-amd64
---
Docker
- Host: [default]
- Version: 1.41
- Builder: 2
---
Kubernetes
- Env: minikube
- Context: minikube
- Cluster Name: minikube
- Namespace: default
- Container Runtime: containerd
- Version: v1.20.7
- Cluster Local Registry: {Host:localhost:56195 hostFromCluster: SingleName:}
@wesleyfr wesleyfr added the bug Something isn't working label Jun 29, 2021
@milas
Copy link
Contributor

milas commented Jun 29, 2021

Thanks for the report - that definitely looks like an issue.

We use (a fork of) a library, and I do see a similar upstream issue: fsnotify/fsnotify#323.

I'll see if I can repro on a Windows box and potentially get a fix into our fork.

@milas
Copy link
Contributor

milas commented Jun 30, 2021

Can you reproduce this reliably? I am not seeing it on my Windows 10 machine. If I open files in Notepad, for example, I can see the LastAccessTimeUtc change while LastWriteTimeUtc stays the same if I query in Powershell. Tilt is NOT triggering a reload based on that (only if I actually change+save), and a test case I wrote against fsnotify code is similarly not getting events emitted for just file access.

In your case, is helm-values.tilt.yaml being generated by an external tool? I'm wondering if, for example, it's getting copied from somewhere else with its attributes retained, so Tilt is seeing the actual filesystem event even though by time it looks like it wasn't edited.

For more context, Tilt watches for actual file system events (create/modify/delete) and does not actually rely on file modification times, as they can be unreliable and have a host of quirks. That said, Tilt trusts the fs events implicitly to mean something did change, see #3690 for discussion over potential improvements to this to consider e.g. file hash to help avoid spurious rebuilds.

@wesleyfr
Copy link
Author

You are right, I have the same behavior as you.

But I noticed that when I change an attribute of the file (for exemple: Read Only) the LastAccessTimeUtc and LastWriteTimeUtc were unchanged but FileWatch was triggered (seenFiles).

We have security tools which maybe change files attributes in background.
I cannot disable them and I cannot create an audit access on files, so I cannot be sure that that's the real problem.

@milas
Copy link
Contributor

milas commented Jun 30, 2021

Ahhh thanks! That makes sense, and is because the file watching code includes attribute changes in its filter but Windows doesn't distinguish between attribute changes and file content changes when it reports the event, so they get lumped in as file writes.

See tilt-dev/fsnotify#8.

@milas milas changed the title FileWatch triggers file changed even if the file was only accessed FileWatch triggers file changed even if only file attributes changed Jun 30, 2021
@milas milas added the Windows label Jun 30, 2021
@milas
Copy link
Contributor

milas commented Jul 6, 2021

This should be fixed in v0.21.1+ - let me know if you still see strange behavior after upgrading

@wesleyfr
Copy link
Author

wesleyfr commented Jul 8, 2021

Thanks a lot for fixing it quickly, I confirm it works !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants