Skip to content

Race condition between ENV modification and backticks causes array out of bounds exception #10031

Open

Description

@katafrakt

Environment Information

  • JRuby 10.0.2.0 and 10.0.3.0 on Linux

Expected Behavior

No out of bounds exception happens.

Actual Behavior

When I run Hanami tests in the CI, every once in a while I see an array out of bounds exception raise. For example here. This goes away after retrying, usually.

I narrowed it down to a race condition between ENV modification and backticks and I'm able to reliably reproduce it with this two-liner:

Thread.new { i = 0; loop { ENV["REPRO_#{i += 1}"] = "x" } }
100.times { `echo` }

This causes:

Unhandled Java exception: java.lang.ArrayIndexOutOfBoundsException: Index 559 out of bounds for length 559
java.lang.ArrayIndexOutOfBoundsException: Index 559 out of bounds for length 559
            buildEnvp at org/jruby/util/io/PopenExecutor.java:1199
  execargParentStart1 at org/jruby/util/io/PopenExecutor.java:1174
   execargParentStart at org/jruby/util/io/PopenExecutor.java:1122
         execargFixup at org/jruby/util/io/PopenExecutor.java:1117
             pipeOpen at org/jruby/util/io/PopenExecutor.java:613
             pipeOpen at org/jruby/util/io/PopenExecutor.java:296
            backquote at org/jruby/RubyKernel.java:1796
  ️❤ {} \=\^main\_ #2 at repro.rb:1
          yieldDirect at org/jruby/runtime/CompiledIRBlockBody.java:151
        yieldSpecific at org/jruby/runtime/IRBlockBody.java:74
        yieldSpecific at org/jruby/runtime/Block.java:160
                times at org/jruby/RubyFixnum.java:338
                 call at org/jruby/RubyInteger$INVOKER$i$0$0$times.gen:-1
                 call at org/jruby/internal/runtime/methods/JavaMethod.java:559
  performIndirectCall at org/jruby/ir/targets/indy/InvokeSite.java:875
               invoke at org/jruby/ir/targets/indy/InvokeSite.java:786
            ️❤ script at repro.rb:2
                  run at repro.rb:-1
  invokeWithArguments at java/lang/invoke/MethodHandle.java:733
                 load at org/jruby/ir/Compiler.java:114
            runScript at org/jruby/Ruby.java:1221
          runNormally at org/jruby/Ruby.java:1133
          runFromMain at org/jruby/Ruby.java:978
          internalRun at org/jruby/Main.java:282
                  run at org/jruby/Main.java:227
                 main at org/jruby/Main.java:199

Unfortunately, I'm not really sure how to proceed from this reproduction to a fix, so I'm opening an issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions