On 7/18/25 10:13 PM, andy pugh wrote:
The same race condition is still present because the 'result' file is
closed (in runtests by the shell) when halrun exists. But we know that
halrun's exit is not enough to prevent the race because halrun must have
exited or 'checkresult' will not be executed.
That makes sense, but appears not to be true.
[snip]

Ah! The stdout of halrun is diverted to 'result' and the children, in this case mb2hal, inherit that file descriptor. That is why it is still open. It will close after the last reference is closed.

An additional test can be in runtests(.in):
----
wait_for_result_close() {
  if ! [ -d "$1" ]; then
    echo "Internal error: Missing or invalid testdir argument to $0"
    exit 2
  fi
  timeoutcnt=0
  while lsof -- "$(realpath "$1/result")" > /dev/null 2>&1; do
    if [ $timeoutcnt -ge 30 ]; then
      echo "*** Timeout waiting for 'result' file to close in '$1'"
      echo "*** Test results may be invalid when checked."
      return 1
    fi
    sleep 1
    timeoutcnt=$((timeoutcnt + 1))
  done
  return 0
}
----

A call:
  wait_for_result_close "$testdir"

should be added in runtests.in just before the popd to:
- run_shell_script()
- run_executable()
- run_without_overruns()


But I am also wondering if that check should be in the "runtests"
script rather than in specific "checkresults" scripts.
That depends on finding a common denominator for _all_ tests that must
be satisfied.
I think that testing for the result file write being complete probably
is universal to files where a result file is expected.
(which is one of a small number of cases in runtests)

See above.

It might be an idea to add a test for the 'stderr' file too?


The fact that this works isn't enough to convince me that it is an
answer, though, for the reasons you outline.
But, clearly, the file is being seen as open even while runtests runs,
and then closes a few milliseconds later.

It works only in cases where child processes do not close the stdout and stderr file descriptors, with the additional condition that if they do, then the checkresult step must use /other/ files to test the validity of the output. When 'result' and 'stderr' files are determining the test's outcome via checkresult, then children closing the descriptors should have no bearing because their output is not considered in the test.

It will work for most scenarios.

Are there /any/ tests that check results on any other output than the 'result' file? If not, then it should work for all scenarios.

--
Greetings Bertho

(disclaimers are disclaimed)



_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to