Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8302000

[11u] A subtle race condition during jdk11u build

XMLWordPrintable

    • b05
    • generic
    • generic

      A recent change to jdk11 has exposed a very subtle race condition during a jdk11u build.

      The fix for JDK-8257679, adds this changeset.
      https://github.com/openjdk/jdk11u/commit/40f4fc2da8532252a1660c7f082eb19046f4bc70
      $(call ExecuteWithLog, $(SUPPORT_OUTPUTDIR)/gensrc/java.base/_charset_decoder, \
      $(TOOL_SPP) < $< >$@.tmp \

      The problem above is two fold:
      The Spp tool reads from stdin and writes to stdout and is missing a set of parenthesis.

      The parenthesis is required otherwise a subtle race condition in the shell will clobber the output, resulting in mysterious build failures. This is consistently reproducible on Windows and if the top-level make is invoked via Python .

      So why is the missing parenthesis a problem ?
      Please read this comment very carefully.
      https://github.com/openjdk/jdk11u/blob/master/make/common/MakeBase.gmk#L1060

      Adding the ExcecuteWithLog will result in a pseudo code as follows:

      Spp < in-file > out-file > (some.log) (blah)
      Notice the second redirection to stdout in the above.

      Now adding a parenthesis will create a subshell and redirect the output (if any) from the tool.
      (Spp < in-file > out-file) > (some.log) (blah)

      There are couple of ways of solving this:
      1. Undo the change introduced by JDK-8257679
      2. Add parenthesis to all those call-sites of Spp with ExecuteWithLog
      3. Back-port the change for Spp and fix the call-sites to use -i and -o arguments instead of reading stdin and writing to stdout.
      https://github.com/openjdk/jdk/blob/master/make/jdk/src/classes/build/tools/spp/Spp.java

      IMHO #3 is the way to go, when the legacy Spp shell script was converted to Java, it should have eliminated the need for stdin/stdout operations and replaced with input/output files.


            ksrini Kumar Srinivasan
            ksrini Kumar Srinivasan
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: