Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

ln -sf only appears as DELETE on linux #102

Open
bobrik opened this issue Jul 8, 2014 · 5 comments
Open

ln -sf only appears as DELETE on linux #102

bobrik opened this issue Jul 8, 2014 · 5 comments

Comments

@bobrik
Copy link

bobrik commented Jul 8, 2014

ln -sf /var/log/scribe/wtf_125 /var/log/scribe/wtf_current

appears as:

2014/07/08 13:28:03 "/var/log/scribe/wtf_current": DELETE

in strace it looks like this:

stat("/var/log/scribe/wtf_current", {st_mode=S_IFREG|0600, st_size=29, ...}) = 0
lstat("/var/log/scribe/wtf_current", {st_mode=S_IFLNK|0777, st_size=23, ...}) = 0
stat("/var/log/scribe/wtf_125", {st_mode=S_IFREG|0600, st_size=29, ...}) = 0
symlink("/var/log/scribe/wtf_125", "/var/log/scribe/wtf_current") = -1 EEXIST (File exists)
unlink("/var/log/scribe/wtf_current")   = 0
symlink("/var/log/scribe/wtf_125", "/var/log/scribe/wtf_current") = 0

At the same time, this works as expected:

rm /var/log/scribe/wtf_current; ln -s /var/log/scribe/wtf_125 /var/log/scribe/wtf_current
2014/07/08 13:29:23 "/var/log/scribe/wtf_current": DELETE
2014/07/08 13:29:23 "/var/log/scribe/wtf_current": CREATE
unlinkat(AT_FDCWD, "/var/log/scribe/wtf_current", 0) = 0
... different process ...
stat("/var/log/scribe/wtf_current", 0x7fffcbc6baa0) = -1 ENOENT (No such file or directory)
symlink("/var/log/scribe/wtf_125", "/var/log/scribe/wtf_current") = 0

The next C program gives correct events with probability ~80%:

#include <unistd.h>

int main() {
    unlink("/var/log/scribe/wtf_current");
    usleep(1);
    symlink("/var/log/scribe/wtf_125", "/var/log/scribe/wtf_current");
    return 0;
}

Removing usleep leads to absence of CREATE events.

I suspect race condition somewhere.

@bobrik
Copy link
Author

bobrik commented Jul 8, 2014

Whoa:

2014/07/08 13:57:43 sending to internalEvent: "/var/log/scribe/wtf/wtf_current": DELETE
2014/07/08 13:57:43 sending to internalEvent: "/var/log/scribe/wtf/wtf_current": CREATE
2014/07/08 13:57:43 purgeEvents event: "/var/log/scribe/wtf/wtf_current": DELETE sendEvent: true
2014/07/08 13:57:43 purgeEvents event: "/var/log/scribe/wtf/wtf_current": CREATE sendEvent: false

@nathany
Copy link
Contributor

nathany commented Jul 8, 2014

Thanks for the thorough bug report with all the steps to reproduce.

Would you mind testing against github.com/fsnotify/fsnotify and opening a new issue at https://github.com/fsnotify/fsnotify/issues/new if the race condition persists?

(See #101)

@bobrik
Copy link
Author

bobrik commented Jul 8, 2014

@nathany I just did, it seems to be working in your version. I migrated to it already, thanks! (Although I'd keep Is* methods in Event).

@nathany
Copy link
Contributor

nathany commented Jul 8, 2014

It is more verbose than when it had the Is* methods. The nice thing is that it's easy to coalesce events together. The API isn't final by any means, but what's at fsnotify/fsnotify is close to what we came up with. (API doc http://goo.gl/MrYxyA)

@nathany
Copy link
Contributor

nathany commented Jul 9, 2014

@tianon I'm thinking of renaming fsnotify/fsnotify one more time. See the conversation here: fsnotify/fsnotify#28. Sorry if your stuff breaks.

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

Successfully merging a pull request may close this issue.

2 participants