karelia / BSManagedDocument

Brings UIManagedDocument's design to OS X
Other
55 stars 25 forks source link

Freezing while saving? #24

Open adib opened 10 years ago

adib commented 10 years ago

Is calling [super saveToURL: ofType saveOperation: error] inside a performAsynchronousFileAccessUsingBlock call a good idea?

My app sometimes freezes at this point and I wonder if there's a re-entrancy issue here:

scuttlebutt__bsmanageddocument_m

I'm on BSManagedDocument 0.3.x commit f7fc8dc

Also the app has a number of documents open concurrently (different package files of course).

mikeabdullah commented 10 years ago

Can you show me the rest of the stack at this point, please?

adib commented 10 years ago

Finally I figured out how to show the full stack traces...

bsmanageddocument_freeze_trace_1

bsmanageddocument_freeze_trace_2

bsmanageddocument_freeze_trace_3

bsmanageddocument_freeze_trace_4

Those were all the threads that were active when the app froze.

At a glance threads 1 and 9 seems to be calling the main thread when this happens. Wonder if the contention is among those two?

adib commented 10 years ago

Just thinking out loud, maybe NSDocument's file coordinator is not setup correctly to handle file packages?

adib commented 10 years ago

This happens during autosave, NSAutosaveInPlaceOperation

adib commented 10 years ago

Apparently the bugger is with file coordination. Although nothing else is supposed to be accessing the file package (and for my case, there shouldn't be any since it's in the apps' Application Support folder and not normally accessible directly by the user), [NSDocument saveToURL: ofType: forSaveOperation: completionHandler: freezes on file coordination and it seems that there's no way to work around it but skipping it altogether.

I have something that's been working OK, will push this out as part of a beta release and see whether there's any negative repercussion for not using NSDocument's save implementation.

Commit: a216aea61e1f7259841542a22c5b903ed21a6a69