From 45d4baf15356d8db10d7ea6367247ff4366cdc14 Mon Sep 17 00:00:00 2001 From: Robert Syme Date: Wed, 4 Jun 2025 00:29:59 +0000 Subject: [PATCH 1/2] Resolve race condition with FIFO cleanup and child process termination --- source/Parameters_closeReadsFiles.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/source/Parameters_closeReadsFiles.cpp b/source/Parameters_closeReadsFiles.cpp index f3a22ab3..b577081c 100644 --- a/source/Parameters_closeReadsFiles.cpp +++ b/source/Parameters_closeReadsFiles.cpp @@ -2,11 +2,32 @@ #include "ErrorWarning.h" #include #include +#include void Parameters::closeReadsFiles() { for (uint imate=0; imatereadIn[imate].is_open() ) inOut->readIn[imate].close(); - if (readFilesCommandPID[imate]>0) - kill(readFilesCommandPID[imate],SIGKILL); + if (readFilesCommandPID[imate]>0) { + kill(readFilesCommandPID[imate],SIGTERM); // Use SIGTERM for graceful shutdown + int status; + waitpid(readFilesCommandPID[imate], &status, 0); // Wait for process to terminate + + // Check if process had issues (but don't fail - this is cleanup) + if (WIFEXITED(status)) { + int exit_code = WEXITSTATUS(status); + if (exit_code != 0) { + warningMessage("readFilesCommand process for mate " + to_string(imate+1) + + " exited with non-zero code: " + to_string(exit_code), + std::cerr, inOut->logMain, *this); + } + } else if (WIFSIGNALED(status)) { + int signal_num = WTERMSIG(status); + if (signal_num != SIGTERM) { // Don't warn about our own SIGTERM + warningMessage("readFilesCommand process for mate " + to_string(imate+1) + + " was terminated by signal: " + to_string(signal_num), + std::cerr, inOut->logMain, *this); + } + } + } }; }; \ No newline at end of file From 296e4dbd2bee2a45563bee9a266bc23f5fdf72cf Mon Sep 17 00:00:00 2001 From: Robert Syme Date: Wed, 4 Jun 2025 00:52:34 +0000 Subject: [PATCH 2/2] Clean up processes BEFORE removing files --- source/STAR.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/STAR.cpp b/source/STAR.cpp index f9b84b3e..fbdc1fca 100755 --- a/source/STAR.cpp +++ b/source/STAR.cpp @@ -292,6 +292,8 @@ int main(int argInN, char *argIn[]) *P.inOut->logStdOut << timeMonthDayTime(g_statsAll.timeFinish) << " ..... finished successfully\n" << flush; + P.closeReadsFiles(); // Clean up processes BEFORE removing files + P.inOut->logMain << "ALL DONE!\n" << flush; if (P.outTmpKeep == "None") @@ -299,7 +301,6 @@ int main(int argInN, char *argIn[]) sysRemoveDir(P.outFileTmp); }; - P.closeReadsFiles(); // this will kill the readFilesCommand processes if necessary // genomeMain.~Genome(); //need explicit call because of the 'delete P.inOut' below, which will destroy P.inOut->logStdOut if (genomeMain.sharedMemory != NULL) { // need explicit call because this destructor will write to files which are deleted by 'delete P.inOut' below