Skip to content

Commit

Permalink
Fix potential deadlock when opening find window
Browse files Browse the repository at this point in the history
The Find object is assigned to a variable with (guarded) static storage, so the initializer of the Find object will run with a lock on the guarded variable, which turns out to be shared with all other guarded variables.

When setting up the window controller, from the Find object’s initializer, we create a “recent folders” menu which hold icons with SCM badges.

When creating these SCM icons, blocks are scheduled (asynchronously) to “fetch status”. These asynchronous blocks will need to lock the same mutex as we currently have locked (because we haven’t yet left the initializer).

The issue is that we also schedule synchronous blocks on the same queue, and that’s why we get a deadlock, because those can’t run before the asynchronous blocks have finished, yet those are waiting on the global lock that our main thread has currently obtained.

Fixes #874.
  • Loading branch information
sorbits committed Mar 7, 2013
1 parent baade85 commit ee2c2b3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Frameworks/Find/src/Find.mm
Expand Up @@ -45,11 +45,10 @@ + (Find*)sharedInstance
return instance;
}

- (id)init
- (FindWindowController*)windowController
{
if(self = [super init])
if(!_windowController)
{
D(DBF_Find_Base, bug("\n"););
self.windowController = [FindWindowController new];
self.windowController.nextResponder = self;
self.windowController.resultsOutlineView.action = @selector(didSingleClickResultsOutlineView:);
Expand All @@ -60,7 +59,7 @@ - (id)init

[self.windowController.window addObserver:self forKeyPath:@"firstResponder" options:0 context:NULL];
}
return self;
return _windowController;
}

// ====================================
Expand Down

1 comment on commit ee2c2b3

@johnheimkes
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this! I ran into this a few times this afternoon.

Please sign in to comment.