Skip to content

Commit

Permalink
Avoid an infinite loop in InitRootHandlers destructor
Browse files Browse the repository at this point in the history
If there is a problem with the list of open files from ROOT such that casting an element to TFile fails the code no longer gets stuck in an infinite loop.
The problem actually happened in the Tier 0 probably due to a threading problem in ROOT.
  • Loading branch information
Dr15Jones committed Nov 18, 2014
1 parent ffb64b0 commit f408898
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions FWCore/Services/src/InitRootHandlers.cc
Expand Up @@ -294,12 +294,16 @@ namespace edm {

InitRootHandlers::~InitRootHandlers () {
// close all open ROOT files
// We get a new iterator each time,
// because closing a file can invalidate the iterator
while(gROOT->GetListOfFiles()->GetSize()) {
TIter iter(gROOT->GetListOfFiles());
TFile* f = dynamic_cast<TFile*>(iter.Next());
if(f) f->Close();
TIter iter(gROOT->GetListOfFiles());
TObject *obj = nullptr;
while(nullptr != (obj = iter.Next())) {
TFile* f = dynamic_cast<TFile*>(obj);
if(f) {
// We get a new iterator each time,
// because closing a file can invalidate the iterator
f->Close();
iter = TIter(gROOT->GetListOfFiles());
}
}
}

Expand Down

0 comments on commit f408898

Please sign in to comment.