Watcher should ignore files not in sources before cancelling any running tasks.#2743
Watcher should ignore files not in sources before cancelling any running tasks.#2743trulede wants to merge 2 commits intogo-task:mainfrom
Conversation
|
@trulede Feel free to bring the tests over here if you like. What about the second half to my original PR to fix the task fingerprinting uniqueness issue? Should I refactor my PR to only have that fix within it. |
|
@mkeeler I've copied over the watch_tests and will get them running and then update this PR. Yes, refactor your PR to have the fix for the checksums. |
Co-authored-by: Oleg Butuzov <butuzov@made.ua> Co-authored-by: Timothy Rule <34501912+trulede@users.noreply.github.com>
208fe5f to
d65f329
Compare
|
I think @andreynering plans to merge this one soon. |
There was a problem hiding this comment.
Thanks for the PR !
In some cases the watch does not work as intended.
Considering this Taskfile :
version: '3'
tasks:
default:
sources:
- "**/*.txt"
cmds:
- echo "Task running!"And those steps to reproduce :
echo initial > a.txt
/tmp/task-repro --watch --verbose > /tmp/repro-watch.log 2>&1 &
sleep 1
echo updated-1 > a.txt
sleep 1
mkdir newdir && echo hello > newdir/new.txt
sleep 2
echo probe > a.txt
sleep 3Observed output
cat /tmp/repro-watch.log
task: Started watching for tasks: default
task: [default] echo "Task running!"
task: watching new dir: .
Task running!
task: task "default" finished running
task: received watch event: WRITE "/tmp/repro-watch/a.txt"
task: [default] echo "Task running!"
Task running!
task: task "default" finished running
task: received watch event: CREATE "/tmp/repro-watch/newdir"
task: watching new dir: newdir
# here you should see an event for the write to a.txt but nothing appear
If I run it with main :
task: Started watching for tasks: default
task: watching new dir: .
task: "default" started
task: [default] echo "Task running!"
Task running!
task: "default" finished
task: task "default" finished running
task: received watch event: WRITE "/tmp/repro-watch2/a.txt"
task: "default" started
task: [default] echo "Task running!"
Task running!
task: "default" finished
task: task "default" finished running
task: received watch event: CREATE "/tmp/repro-watch2/newdir"
task: skipped for file not in sources: newdir
task: received watch event: WRITE "/tmp/repro-watch2/a.txt"
task: "default" started
task: [default] echo "Task running!"
Task running!
task: "default" finished
task: task "default" finished running
task: watching new dir: newdir|
That is a race condition in the underlying watcher (I believe). Its been there for a while. The directory and file are created close together, such that the directory is not added until after the file WRITE event of the file. Therefore it is missed. There is currently a go routine, which runs on an interval, and rebuilds/rescans the watcher and picks up these new directories. So, after a period of time, the watcher should trigger on the new directory (and its contained files). That code pre-existed this PR. However, this PR does improve the rescan algorithm so that deleted and recreated directories are correctly handled. Previously, a deleted directory handle in the watcher would become stale, and recreated directories would never trigger watch events. The race condition might be solved in a subsequent PR, after refactoring out of some duplicated code. However its also possible that the existing periodic rescan is actually the only solution. It depends somewhat on the order that watcher events are raised (the order not always what you think). |
Fix several issues with the watcher:
Additional tests are added to cover most normal conditions.
watchissue #2715