accounts/keystore: fix cache update and TestUpdatedKeyfileContents fa…#15410
accounts/keystore: fix cache update and TestUpdatedKeyfileContents fa…#15410gbotrel wants to merge 2 commits into
Conversation
| filesNow.Add(path) | ||
| if modTime.After(prevMtime) { | ||
| // on macOS, we get FS notifications before the actual modTime is updated | ||
| if modTime.After(prevMtime) || (modTime.Equal(prevMtime) && runtime.GOOS == "darwin") { |
There was a problem hiding this comment.
Maybe a better fix would be to use modTime.After(prevMtime) || modTime.Equal(prevMtime) on all platforms.
Does that sound good to you?
There was a problem hiding this comment.
Yes if we want to avoid platform specific code, I believe the perf impact is negligible
|
This means rescanning the entire directory again, which is one of the basic problems I wanted to avoid. It is non-neglible when there are hundreds of thousands of accounts. So if there's any other way of doing it (e.g differebt lib), I'd prefer that. Alternatively, keep this fix as a mac only solution. My 5 c. |
|
Does it? (= rescan the entire directory). My understanding is that this scan is now triggered only after a FS event is thrown. Meaning something did effectively change in the directory --> meaning iteration i+2 will likely update the new reference modified time: and all the files not changing their modTime won't be picked again. This was a quick fix, I agree there are more elegant solutions (see first comment --> what about using EventInfo data that contains the path of the file that changed ? but that does change much more than just a line of code) |
|
Please remove travis-related changes from this PR. |
5736f02 to
6407276
Compare
|
Did remove the guilty commits with a history rewrite, please ignore GitCop messages :-) |
So, the However, that makes me question if this fix will work. Consider the following:
Or is there another fs-event triggered once the |
|
Could the problem be that the mtime has only resolution on seconds? Another PR was merged which changed times to 1s in the tests. So this might be fixed already |
|
This one: #15498. |
|
The other PR don't seem to fix the underlying problem --> the test will pass, but the scenario we mentioned here can still happen and result in a cache not being updated. I agree with your previous comment, my fix is not enough for this to be bulletproof, what about using the EventInfo from notify library? If I have some time will run some tests the coming days. |
|
I'll make a PR using the EventInfo thing, and hopefully the buildsystem can tell us how cross-platform portable it is. |
|
@gbotrel I can't reproduce the issues myself, but if you're on a Mac, you're more than welcome to test my PR (linked above) and see if it fixes the issue for you. |
|
@holiman --> did test your PR #15580 on mac, runs fine 👍 . But it has the other PR (#15498 ) changes in it, making the test quite longer than it was. And the tests pass. I believe adding the sleeps was just hiding the test failure, and your PR solves the actual underlying problem. Closing this PR . |
|
Great, thanks for reporting! I'll change those values back, and clean up the PR, and mark it as no-longer-wip. |
fix cache update and TestUpdatedKeyfileContents failing on macOS.
TestUpdatedKeyfileContents was randomly failing on macOS. Root cause: after writing to a file and closing the file handle, we get the fs notify event, we scan the directory and the modified time of the file is not yet updated (and the scanAccount logic relies on that to update the cache), even after the 500ms delay in watch.go.
I believe using the EventInfo from notify library in watch.go:93 to avoid scanning directory and relying on modified time of files would be safer (the event contains the Modified / Created / Deleted file path, yet we scan the whole directory and compare modified times)