From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 0F87A1F4B4 for ; Tue, 29 Sep 2020 15:18:02 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 3F3B5120A8B; Wed, 30 Sep 2020 00:17:22 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 56677120A8A for ; Wed, 30 Sep 2020 00:17:19 +0900 (JST) Received: by filterdrecv-p3las1-6f66587546-ttjj9 with SMTP id filterdrecv-p3las1-6f66587546-ttjj9-18-5F73501F-8D 2020-09-29 15:17:51.717617974 +0000 UTC m=+667148.795419597 Received: from herokuapp.com (unknown) by ismtpd0092p1mdw1.sendgrid.net (SG) with ESMTP id dMEgOn1_RWKnuQ-Nwpgg7g for ; Tue, 29 Sep 2020 15:17:51.565 +0000 (UTC) Date: Tue, 29 Sep 2020 15:17:51 +0000 (UTC) From: maciej@mensfeld.pl Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76057 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17203 X-Redmine-Issue-Author: maciej.mensfeld X-Redmine-Sender: maciej.mensfeld 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: =?us-ascii?Q?1UVFNop+J46xJRgKT91tQd4fJmTtITnXW0zIvVfv30Dihzjx8FPZkxOK6ugvhL?= =?us-ascii?Q?VgP8+l69qZYMKOkqlhD2VDa7rRbprSeVkVFnsqW?= =?us-ascii?Q?XILxr0PsMRxD=2Fpx=2FG5tznb5v8=2FQwRhcv3KPkEoH?= =?us-ascii?Q?DbAshEQfEh12L8q3F6onSNf9O+IxFZEdO4Ty1PH?= =?us-ascii?Q?tOZ3cAathHY0=2FJci6g9+rvn=2FwoazmKNmqewJc9N?= =?us-ascii?Q?URtt8m2mAXZaDmrls=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 100216 Subject: [ruby-core:100216] [Ruby master Bug#17203] Logger::Formatter won't work with non main Ractor 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17203 has been reported by maciej.mensfeld (Maciej Mensfeld). ---------------------------------------- Bug #17203: Logger::Formatter won't work with non main Ractor https://bugs.ruby-lang.org/issues/17203 * Author: maciej.mensfeld (Maciej Mensfeld) * Status: Open * Priority: Normal * ruby -v: ruby 3.0.0preview1 (2020-09-25 master 0096d2b895) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- ``` ruby class Rogger < Ractor def self.new super do # STDOUT cannot be referenced but $stdout can logger = ::Logger.new($stdout) # Run the requested operations on our logger instance while data = recv logger.public_send(data[0], *data[1]) end end end # Really cheap logger API :) def method_missing(m, *args, &_block) self << [m, *args] end end class Rails LOGGER = Rogger.new def self.logger LOGGER end end Ractor.new do Rails.logger.info "Hello" end ``` running this ends up with: ```bash terminated with exception (report_on_exception is true): ruby/3.0.0/logger/formatter.rb:15:in `call': can not access global variables $$ from non-main Ractors (RuntimeError) from ruby/3.0.0/logger.rb:586:in `format_message' from ruby/3.0.0/logger.rb:476:in `add' from ruby/3.0.0/logger.rb:529:in `info' from test.rb:23:in `public_send' from test.rb:23:in `block in new' ``` however the same with fixed formatter works. PR: https://github.com/ruby/ruby/pull/3600 All of the code examples are here: https://mensfeld.pl/2020/09/building-a-ractor-based-logger-that-will-work-with-non-ractor-compatible-code/ -- https://bugs.ruby-lang.org/