Skip to content

Commit

Permalink
Fixed dead-lock #297
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Oct 12, 2024
1 parent d74a530 commit d1e3d1a
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager;
import com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint;
import com.helger.phoss.smp.domain.serviceinfo.ISMPProcess;
import com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation;
import com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager;
import com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint;
import com.helger.phoss.smp.ui.AbstractSMPWebPage;
Expand Down Expand Up @@ -119,7 +120,8 @@ public LongRunningJobResult createLongRunningJobResult ()
// Modify all endpoints
final MutableInt aChangedEndpoints = new MutableInt (0);
final MutableInt aSaveErrors = new MutableInt (0);
final ICommonsSortedSet <String> aChangedServiceGroup = new CommonsTreeSet <> ();
final ICommonsList <ISMPServiceInformation> aChangedSIs = new CommonsArrayList <> ();
// Run in a read-lock
aServiceInfoMgr.forEachSMPServiceInformation (aSI -> {
if (m_aServiceGroup != null && !aSI.getServiceGroup ().equals (m_aServiceGroup))
{
Expand All @@ -138,12 +140,20 @@ public LongRunningJobResult createLongRunningJobResult ()
}
if (bChanged)
{
if (aServiceInfoMgr.mergeSMPServiceInformation (aSI).isFailure ())
aSaveErrors.inc ();
aChangedServiceGroup.add (aSI.getServiceGroupID ());
// Remember and do not merge here to avoid deadlock
aChangedSIs.add (aSI);
}
});

// Write out of read-lock
final ICommonsSortedSet <String> aChangedServiceGroup = new CommonsTreeSet <> ();
for (final var aSI : aChangedSIs)
{
if (aServiceInfoMgr.mergeSMPServiceInformation (aSI).isFailure ())
aSaveErrors.inc ();
aChangedServiceGroup.add (aSI.getServiceGroupID ());
}

final IHCNode aRes;
if (aChangedEndpoints.isGT0 ())
{
Expand Down

0 comments on commit d1e3d1a

Please sign in to comment.