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

Double firing of event #324

Closed
riccardomanfrin opened this issue Feb 10, 2020 · 11 comments
Closed

Double firing of event #324

riccardomanfrin opened this issue Feb 10, 2020 · 11 comments
Labels

Comments

@riccardomanfrin
Copy link

riccardomanfrin commented Feb 10, 2020

Before reporting an issue, please ensure you are using the latest release of fsnotify.

Which operating system (GOOS) and version are you using?

Linux:
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic

fsnotify version: ## v1.4.7 / 2018-01-09

Please describe the issue that occurred.

Modifying a file either with

 echo "helloworld" > /my/tmp/file

or by means of a generic editor (vim/nano/sublime) generates single or double OP 0x2 events on a random base (say 50% of the times I get single OP 0x2 events, and the other half I get the event twice).

Are you able to reproduce the issue? Please provide steps to reproduce and a code sample if possible.

Full code reference @ https://medium.com/@skdomino/watch-this-file-watching-in-go-5b5a247cf71f

This is the sensible part:

var watcher *fsnotify.Watcher

//Listen on file changes
func Listen() {
	defer watcher.Close()
	done := make(chan bool)

	go func() {
		for {
			select {
			// watch for events
			case event := <-watcher.Events:
				res, err := Read(&event.Name)
				if err != nil {
					continue
				}
				fmt.Printf("EVENT! %#v\n", event)
				logger.Log.Debug(*res)
				// watch for errors
			case err := <-watcher.Errors:
				logger.Fatal(err)
			}
		}
	}()

	<-done
}
@snowyyj001
Copy link

I user the example code for test and it also trigger two times, it happened 100%.
if ev.Op&fsnotify.Write == fsnotify.Write {
//here will be called two times
}

@zhaocy
Copy link

zhaocy commented Feb 27, 2020

I had the same problem running the sample。 on windows 7 operation system

@dmgcodevil
Copy link

in my case, it fires 10+ events. mac os. go 1.13

@dkotik
Copy link

dkotik commented Mar 20, 2020

Ubuntu 19.10 double firing for me as well.

@riccardomanfrin
Copy link
Author

best way to keep it under control is to md5sum compare changes

@chenqinghe
Copy link

windows 10, go1.14 double firing too.

@ellis2323
Copy link

windows 10 (version 2004), go1.14 double firing as well

@PaluMacil
Copy link

same double READ result, Ubuntu 20.04

@sgon00
Copy link

sgon00 commented Mar 11, 2021

Debian 10 (MX Linux), Go 1.16.
I don't see double firing by using echo command when modifying the file.
But I see double firing when using rich editors such as vscode.

Possible Related Issues:
#122
microsoft/vscode#9419

@flysand7
Copy link

Windows 10, go 1.17.2
My experience matches that of @sgon00. When I use echo and pipe redirects, the firing only happens once.
But when I use sublime text to modify the file, it fires two times at a time.

@arp242
Copy link
Member

arp242 commented Jul 30, 2022

I'm closing this as a duplicate of #372; as mentioned in that issue, many editors don't "just" write a file, but will instead write it to a new file and then rename it.

Also, #470 should make things a little but more consistent, on Linux at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests