Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-42228

MTR tests fail with "File already exist" for .expect files on Windows

    XMLWordPrintable

Details

    Description

      Running MTR tests on Windows with a high enough parallel=N leads to the errors like

      mysqltest: At line 242: File already exist: 'c:/home/Builds/bb-10.11-elenst/mysql-test/var/3/tmp/mysqld.2.expect'
       
      worker[12] mysql-test-run: WARNING: unlink(c:/home/Builds/bb-10.11-elenst/mysql-test/var/12/tmp/mysqld.2.expect) failed: Permission denied
      

      The warning appears to be cosmetic, but the error causes tests failures.

      Claude's analysis:

      • On Windows, the mtr workers aren't separate processes. Perl emulates fork() with threads, so all workers run in one perl.exe and share one table of open
        file handles. lib/My/SafeProcess/Base.pm:87-92 loads threads on Windows for exactly that reason.
      • mtr starts every server and mysqltest with system(1, ...) (Base.pm:154). That passes all inheritable handles of the perl.exe process to the child. The
        $win32_spawn_lock around it only stops two spawns from overlapping; it doesn't stop another worker from having a file open at that moment.
      • Perl's open() on Windows creates inheritable handles, and I believe they are opened without FILE_SHARE_DELETE.
      • Worker B reads its .expect file in check_expected_crash_and_restart → mtr_lastlinesfromfile (lib/mtr_io.pl:104). If worker A starts a server during that
        short window, A's safe_process and mysqld get a copy of B's handle. They keep it until that server stops, which can be minutes later.
      • While A's server holds it, B's unlink fails with a sharing violation, which Perl reports as "Permission denied". The file stays, and B's next --write_file
        fails with "already exist".
      • Once A's server is restarted or stopped, the file can be deleted. That explains why the hold lasts anywhere from seconds to minutes, and why the cleanup
        sometimes succeeds and sometimes warns.

      Fix

      Read the .expect file while holding the same spawn lock, so no process can start while it is open. Add a helper in Base.pm, where the lock variable is
      visible:

        # Read a file while no child process can be spawned, so the handle
        # is not inherited by another worker's child (Windows: workers are threads)
        sub read_file_lines {
          my ($file)= @_;
          lock($win32_spawn_lock);
          open(my $fh, "<", $file) or return;
          my @lines= <$fh>;
          close $fh;
          return @lines;
        }
      

      check_expected_crash_and_restart then gets the last line through it instead of mtr_lastlinesfromfile.

      Attachments

        Issue Links

          Activity

            People

              wlad Vladislav Vaintroub
              elenst Elena Stepanova
              Vladislav Vaintroub Vladislav Vaintroub
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.