From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id DE42619C001F for ; Wed, 28 Oct 2015 14:26:47 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 64BD2B5D884 for ; Wed, 28 Oct 2015 14:54:41 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 7747F952439 for ; Wed, 28 Oct 2015 14:54:41 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 61A031204CD; Wed, 28 Oct 2015 14:54:37 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 7CCD11204C2 for ; Wed, 28 Oct 2015 14:54:33 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=yxysv1Gx9eERnnQ0Ti76AbxhHGI=; b=DMgTpNGAts4v4YG5c3 LXimPqx0eGu1zUFeIiiuMm+VhRB3QHf27t6uKeo1okALOzuaHpcooJHvIC6asrCE +Hu/eyvB/dqkQusApioLHMi6bGZRhQss7Su6rRZQshvF/uBLC2Xus/uOsJzttGd4 srqumtpybR2kDnTw5gIBQT51o= Received: by filter0629p1mdw1.sendgrid.net with SMTP id filter0629p1mdw1.2916.563063163 2015-10-28 05:54:30.019684489 +0000 UTC Received: from herokuapp.com (ec2-54-81-127-246.compute-1.amazonaws.com [54.81.127.246]) by ismtpd0004p1iad1.sendgrid.net (SG) with ESMTP id gqD21L0bTfqB_401tYa_AQ for ; Wed, 28 Oct 2015 05:54:29.877 +0000 (UTC) Date: Wed, 28 Oct 2015 05:54:29 +0000 From: shugo@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 45868 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11384 X-Redmine-Issue-Author: normalperson X-Redmine-Sender: shugo X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS7C9O4XKm2BGM6Dku3flRg76sJRP+5FinQ+8R PV/xEUC7+IXJznKUl/us9QQYud3E93iZCIN/ZPPcx+ZSHXpSNAqII539UWvl+bWjhVjd5lSa9Xkw1m F9WvCvUCkM1uXJE= X-ML-Name: ruby-core X-Mail-Count: 71239 Subject: [ruby-core:71239] [Ruby trunk - Bug #11384] multi-threaded autoload sometimes fails X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11384 has been updated by Shugo Maeda. Eric Wong wrote: > Eric Wong wrote: > > Currently testing this in a loop: > > http://80x24.org/spew/m/94541be0225540e34f0196e9754ae0eb5c07a4b7.txt > > Nope, the original failure still happens with this, so there's > some other place where we're racing :< TestAutoload#test_threaded_accessing_constant has failed often since r52139, and it seems to be the same problem. I could reproduce the problem easily by the following script: ``` require "tempfile" Tempfile.create(['autoload', '.rb']) {|file| file.puts 'sleep(0.5); class AutoloadTest; X = 1; end' file.close 1.upto(Float::INFINITY) do |i| p i autoload(:AutoloadTest, file.path) begin t1 = Thread.new { ::AutoloadTest::X } t2 = Thread.new { ::AutoloadTest::X } [t1, t2].each(&:join) ensure if Object.const_defined?(:AutoloadTest) Object.send(:remove_const, :AutoloadTest) $".pop end end end } ``` The script causes an error within 100 times on My Ubuntu 14.04 box, but it runs over 10,000 times with your patch. Your patch looks good to me, and at least it solves the race condition of autoload_require(), even if there's still another race condition. Why don't you commit it? ---------------------------------------- Bug #11384: multi-threaded autoload sometimes fails https://bugs.ruby-lang.org/issues/11384#change-54616 * Author: Eric Wong * Status: Open * Priority: Normal * Assignee: * ruby -v: trunk r51319 * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- ~~~ I get this failure once in a blue moon: #8 test_autoload.rb:46:in `': open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"} autoload :ZZZ, "./zzz.rb" t1 = Thread.new {ZZZ.ok} t2 = Thread.new {ZZZ.ok} [t1.value, t2.value].join #=> "" (expected "okok") stderr output is not empty bootstraptest.tmp.rb:5:in `block in
': uninitialized constant ZZZ (Name +Error) test_autoload.rb FAIL 1/8 FAIL 1/1010 tests failed It is a very rare failure, I extracted it into a standalone script and it took over 500,000 runs to hit it: unless test(?e, "zzz.rb") open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"} end autoload :ZZZ, "./zzz.rb" t1 = Thread.new {ZZZ.ok} t2 = Thread.new {ZZZ.ok} [t1.value, t2.value].join ~~~ I'll work on this when I find time, but maybe somebody else can look at it sooner. I'm not sure if it affects older versions. -- https://bugs.ruby-lang.org/