test/model subprocess wait fails with EINTR on macOS

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor - P4
    • WT12.0.0, 9.1.0-rc0
    • Affects Version/s: None
    • Component/s: Test Model
    • None
    • Storage Engines - Persistence
    • 50.096
    • SE Persistence backlog
    • None

      Summary

      test_model_rts aborts on macOS in subprocess_helper::wait_if_parent():

      test_model_rts: FAILED: void subprocess_helper::wait_if_parent()/145: waitpid(_child_pid, &status, 0) > 0
      test_model_rts: process aborting
      

      The waitpid call fails with EINTR (errno 4, confirmed under a debugger).

      Root cause

      In test/model/test/common/subprocess.cpp:

      • subprocess_helper::subprocess_helper() installs a SIGCHLD handler with sigaction and a zeroed struct sigaction, so sa_flags does not include SA_RESTART.
      • handler_sigchld() itself calls wait(NULL), so the handler reaps the child.
      • wait_if_parent() then calls waitpid(_child_pid, ...) and asserts the return value is positive.

      The parent's waitpid therefore races the signal handler. Without SA_RESTART it is interrupted by SIGCHLD and returns EINTR; if the handler wins the race and reaps first, it returns ECHILD. Neither is a real failure, but the assertion treats both as fatal.

      Solution

      Retry the wait on EINTR, and accept ECHILD since the handler legitimately reaps the child:

      void
      subprocess_helper::wait_if_parent()
      {
          if (parent()) {
              int status;
              pid_t pid;
      
              /*
               * The SIGCHLD handler reaps the child itself, and it is installed without SA_RESTART, so
               * this wait can either be interrupted by the signal or find the child already gone.
               */
              while ((pid = waitpid(_child_pid, &status, 0)) < 0 && errno == EINTR)
                  ;
              testutil_assert(pid > 0 || errno == ECHILD);
          }
      }
      

      This also needs #include <cerrno> in the same file, and SIGCHLD added to dist/s_string.ok for the new comment.

      Notes

      This was found while working on WT-15324 (test/model fails on macOS). It is currently latent: on macOS every test/model binary aborts earlier in decode_utf8, so test_model_rts never reaches this code. Fixing WT-15324 unmasks it, which is why it is split out here and should land first.

      Definition of Done

      • test_model_rts no longer aborts in wait_if_parent() on macOS.
      • The existing test/model suite still passes on Linux in Evergreen.
      • dist/s_all (or the targeted style checks) passes on the changed files.

            Assignee:
            Etienne Petrel
            Reporter:
            Etienne Petrel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: