Skip to content

Commit

Permalink
Merge branch 'v2.8' into v2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniBussi committed May 16, 2024
2 parents cdfa322 + 6a7fb79 commit 9a827e9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/v2.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ Changes from version 2.7 which are relevant for users:
- Small fix in Python, where we do not assume anymore that strings are null terminated.
- Environment variables such as `PLUMED_INCLUDEDIR` and similar are sanitized before they are used for running commands.
- Fixed a bug leading to a crash when using python selectors (e.g., `@mda:` or `@mdt:`) and multiple MPI processes per replica.
- Fixed leaks in Subprocess, potentially givin problems with a large number (>250) of sequentially created plumed objects all of them using `@mda:` or `@mdt:` selectors.

1 change: 1 addition & 0 deletions regtest/basic/rt-make-subprocess/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../scripts/test.make
2 changes: 2 additions & 0 deletions regtest/basic/rt-make-subprocess/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type=make
plumed_needs=subprocess
31 changes: 31 additions & 0 deletions regtest/basic/rt-make-subprocess/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "plumed/tools/Subprocess.h"
#include <fstream>
#include <unistd.h>

using namespace PLMD;

int main(){
// if processes are not properly terminated and cleaned
// only a finite number of them will be allowed

std::ofstream ofs("should_be_empty");

// the number of iteration required to trigger the bugs fixed in
// 2d45954bbb26471eaf48c72d9a9f0a2dcd8536cc
// are, on MacOS:
// ~ 250 for the missing close call
// ~ 2500 for the missing waitpid call

// notice that we are not spawning simultaneous processes.
// they are called in a sequential way and killed (by destructor)
for(unsigned i=0;i<10000;i++) {
try {
Subprocess sp("yes");
} catch(...) {
ofs<<"failed after "<<i<<"\n";
break;
}
}
return 0;
}

Empty file.
17 changes: 13 additions & 4 deletions src/tools/Subprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifdef __PLUMED_HAS_SUBPROCESS
#include <unistd.h>
#include <csignal>
#include <sys/wait.h>
#endif

namespace PLMD {
Expand Down Expand Up @@ -59,7 +60,11 @@ class SubprocessPid {
}
~SubprocessPid() {
// this is apparently working also with MPI on Travis.
if(pid!=0 && pid!=-1) kill(pid,SIGINT);
if(pid!=0 && pid!=-1) {
int status;
kill(pid,SIGINT);
waitpid(pid, &status, 0); // Wait for the child process to terminate
}
}
#endif
};
Expand Down Expand Up @@ -113,11 +118,15 @@ Subprocess::Subprocess(const std::string & cmd) {

Subprocess::~Subprocess() {
#ifdef __PLUMED_HAS_SUBPROCESS
// fpc should be closed to terminate the child executable
// close files:
fclose(fppc);
fclose(fpcp);
// fclose also closes the underlying descriptors,
// so this is not needed:
close(fpc);
// fcp should not be closed because it could make the child executable fail
/// TODO: check if this is necessary and make this class exception safe!
close(fcp);
// after closing the communication, the subprocess is killed
// in pid's destructor
#endif
}

Expand Down

1 comment on commit 9a827e9

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

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

Found broken examples in automatic/a-masterclass-22-09.txt
Found broken examples in automatic/a-masterclass-22-11.txt
Found broken examples in automatic/a-masterclass-22-12.txt
Found broken examples in automatic/performance-optimization.txt
Found broken examples in automatic/a-trieste-6.txt
Found broken examples in automatic/munster.txt
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in MiscelaneousPP.md

Please sign in to comment.