Skip to content

Commit da2df65

Browse files
Fixed deadlock in -collectDirtyChildren:
By no longer holding a lock while recursing, we allow other threads who may be waiting on the current object to progress before iterating to children of the object, solving some of the deadlocks that we've seen in issues #11, #61, and #299. This does not necessarily fix the above issues, as we probably still have similar deadlocks elsewhere in the codebase. cc @grantland
1 parent d311b20 commit da2df65

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Parse/PFObject.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ + (void)collectDirtyChildren:(id)node
263263

264264
} else if ([node isKindOfClass:[PFObject class]]) {
265265
PFObject *object = (PFObject *)node;
266+
NSDictionary *toSearch = nil;
266267

267268
@synchronized ([object lock]) {
268269
// Check for cycles of new objects. Any such cycle means it will be
@@ -288,18 +289,19 @@ + (void)collectDirtyChildren:(id)node
288289
// Recurse into this object's children looking for dirty children.
289290
// We only need to look at the child object's current estimated data,
290291
// because that's the only data that might need to be saved now.
291-
[self collectDirtyChildren:object->_estimatedData.dictionaryRepresentation
292-
children:dirtyChildren
293-
files:dirtyFiles
294-
seen:seen
295-
seenNew:seenNew
296-
currentUser:currentUser];
297-
298-
if ([object isDirty:NO]) {
299-
[dirtyChildren addObject:object];
300-
}
292+
toSearch = [object->_estimatedData.dictionaryRepresentation copy];
301293
}
302294

295+
[self collectDirtyChildren:toSearch
296+
children:dirtyChildren
297+
files:dirtyFiles
298+
seen:seen
299+
seenNew:seenNew
300+
currentUser:currentUser];
301+
302+
if ([object isDirty:NO]) {
303+
[dirtyChildren addObject:object];
304+
}
303305
} else if ([node isKindOfClass:[PFFile class]]) {
304306
PFFile *file = (PFFile *)node;
305307
if (!file.url) {

0 commit comments

Comments
 (0)