Project

General

Profile

Actions

Bug #17349

open

Rake での並行実行における正規表現マッチングの異常

Added by shuujii (Shuji KOBAYASHI) 11 months ago. Updated 2 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
[ruby-dev:50972]

Description

小さな再現コードが作成できなかったのですが、以下のように Rake で並行実行すると正規表現のマッチングがおかしくなることがあるように見えます。

再現手順

$ git clone https://github.com/mruby/mruby
$ cd mruby
$ git checkout 0cb3a718
$ rake -m CONFIG=boxing clean gensym
Cleaned up target build folder
GEN   build/boxing-no-m64-i32/presym
GEN   build/boxing-no-m64-i32/include/mruby/presym.inc
GEN   build/boxing-no-m32-i32/presym
GEN   build/boxing-no-m32-i64/presym
(snip)
rake aborted!
NoMethodError: undefined method `*' for nil:NilClass
/mruby/tasks/presym.rake:81:in `block (4 levels) in <top (required)>'
/mruby/tasks/presym.rake:80:in `map'
/mruby/tasks/presym.rake:80:in `block (3 levels) in <top (required)>'
/mruby/tasks/presym.rake:69:in `map'
/mruby/tasks/presym.rake:69:in `block (2 levels) in <top (required)>'
Tasks: TOP => gensym => /mruby/build/boxing-no-m64-i64/presym
(See full trace by running task with --trace)
rake aborted!

エラーが発生しているのは以下の部分です。

https://github.com/mruby/mruby/blob/13fc5034345ae159f034849cb3f235f4463edd45/tasks/presym.rake#L80-L82

prefixsuffix の値がおかしくなっているために、macro_to_symbol[[prefix, suffix]]nil なり例外になっています。本来であればこの値は nil にならないはずのものです。

補足

  • rake-m を付けないで並行実行にしなければ発生しません。
  • こちらの環境では少なくとも30回に1回くらいは上記のエラーが発生します。
  • 正規表現のマッチ結果は上記とは違う異常になることもあるようです。

Files

cfiles.rb (33.6 KB) cfiles.rb self contained example of bug jeremyevans0 (Jeremy Evans), 08/13/2021 08:12 PM

Related issues

Related to Ruby master - Bug #17507: Regexp capture groups ignored sometimes in some multithreaded environments (possible race condition)ClosedActions
Actions #1

Updated by jeremyevans0 (Jeremy Evans) 9 months ago

  • Related to Bug #17507: Regexp capture groups ignored sometimes in some multithreaded environments (possible race condition) added

Updated by jeremyevans0 (Jeremy Evans) 2 months ago

I reviewed the mruby presym.rake file and was able to come up with a self contained reproducible example, which I have attached. I confirmed the issue is still present in Ruby 3.0 (this error shows the issue happened between 600 and 1200 iterations):

$ ruby cfiles.rb
......#<Thread:0x00000747b72298f8 cfiles.rb:16 run> terminated with exception (report_on_exception is true):
cfiles.rb:59:in `block (3 levels) in <main>': undefined method `*' for nil:NilClass (NoMethodError)
        from cfiles.rb:58:in `map'
        from cfiles.rb:58:in `block (2 levels) in <main>'
        from cfiles.rb:47:in `map'
        from cfiles.rb:47:in `block in <main>'
        from cfiles.rb:20:in `block (2 levels) in a'
^Ccfiles.rb:26:in `join': Interrupt
        from cfiles.rb:26:in `map'
        from cfiles.rb:26:in `a'
        from cfiles.rb:64:in `<main>'

I also confirmed that https://github.com/ruby/ruby/pull/4734, which fixes #17507, also fixes this issue. With that pull request, the attached example program runs all 60,000 iterations without error.

Actions

Also available in: Atom PDF