Skip to content

Commit

Permalink
do unlock in finally; prevent deadlocks when excetion is thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
wea_ondara committed Feb 14, 2016
1 parent fd3650c commit a923efa
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/main/java/net/alpenblock/bungeeperms/CleanupTask.java
Expand Up @@ -11,19 +11,23 @@ public void run()
long threshold = bp.getConfig().getCleanupThreshold() * 1000;

pm.getUserlock().writeLock().lock();

for(User u : pm.getUsers())
try
{
if((bp.getConfig().isUseUUIDs() ? bp.getPlugin().getPlayer(u.getUUID()) : bp.getPlugin().getPlayer(u.getName())) != null)
{
continue;
}
if(u.getLastAccess() + threshold < System.currentTimeMillis())
for(User u : pm.getUsers())
{
pm.removeUserFromCache(u);
if((bp.getConfig().isUseUUIDs() ? bp.getPlugin().getPlayer(u.getUUID()) : bp.getPlugin().getPlayer(u.getName())) != null)
{
continue;
}
if(u.getLastAccess() + threshold < System.currentTimeMillis())
{
pm.removeUserFromCache(u);
}
}
}

pm.getUserlock().writeLock().unlock();
finally
{
pm.getUserlock().writeLock().unlock();
}
}
}

0 comments on commit a923efa

Please sign in to comment.