开发者

FSEvents mysteriously fails to deliver events in some folders

this is killing me, and I'm not sure I know how to approach debugging it.

I'm using Mac FSEvents API to monitor a given folder on the file system. However, occasionally, some folders stop sending any notification events. So far, this has only happened for folders inside ~/Dropbox, and has affected just a few users of my app (and also regularly affects me as well).

The crazy part is that the way to 'cure' the file system is to do:

mv ~/Dropbox/some/stuck/folder ~/Dropbox/some/stuck/folder.0
mkdir ~/Dropbox/some/stuck/folder
mv ~/Dropbox/some/stuck/folder.0/* ~/Dropbox/some/stu开发者_如何学编程ck/folder/
rmdir ~/Dropbox/some/stuck/folder.0

After running these commands, the folder gets unstuck and starts sending events! It takes a few tries to find which of the parent folders is the culprit, but it's always some folder inside Dropbox. (Quitting Dropbox or rebooting does not cure it.)

I'm doing nothing special in my code. Monitoring is started using:

FSEventStreamContext context;
context.version = 0;
context.info = self;
context.retain = NULL;
context.release = NULL;
context.copyDescription = NULL;

_streamRef = FSEventStreamCreate(nil,
                                 (FSEventStreamCallback)FSMonitorEventStreamCallback,
                                 &context,
                                 (CFArrayRef)paths,
                                 kFSEventStreamEventIdSinceNow,
                                 0.25,
                                 kFSEventStreamCreateFlagUseCFTypes);
if (!_streamRef) {
    NSLog(@"Failed to start monitoring of %@ (FSEventStreamCreate error)", _path);
}

FSEventStreamScheduleWithRunLoop(_streamRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
if (!FSEventStreamStart(_streamRef)) {
    NSLog(@"Failed to start monitoring of %@ (FSEventStreamStart error)", _path);
}

and the callback looks like this (not that it matters):

static void FSMonitorEventStreamCallback(ConstFSEventStreamRef streamRef, FSMonitor *monitor, size_t numEvents, NSArray *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]) {
    for (int i = 0; i < numEvents; i++) {
        NSString *path = [eventPaths objectAtIndex:i];
        FSEventStreamEventFlags flags = eventFlags[i];
        [monitor sendChangeEventWithPath:path flags:flags];
    }
}

Happens on both 10.6 and 10.7. No fancy stuff like FileVault is active.

This does look like an OS bug to me, but I haven't found any mentions of this problem on the web.

Questions are:

1) Have you ever experienced something like this? Any findings?

2) What would be the steps to further diagnose this before using a tech support incident?


This is a known "FSEvents" bug in OS X. It can create all sorts of problems that are hard to track down. See this page for more information about the issue. In particular, the page has a link to a GitHub repo with a utility to find all directories on your machine susceptible to the issue (which need not be in your DropBox folder).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜