[前][次][番号順一覧][スレッド一覧]

ruby-changes:70863

From: Koichi <ko1@a...>
Date: Fri, 14 Jan 2022 18:33:37 +0900 (JST)
Subject: [ruby-changes:70863] 53a4e10146 (master): clear `@result` after `setup_message`

https://git.ruby-lang.org/ruby.git/commit/?id=53a4e10146

From 53a4e101465a4d2ae38ea3bfd3cb7dd3c9f12f61 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Fri, 14 Jan 2022 17:36:49 +0900
Subject: clear `@result` after `setup_message`

For the remote object `ro`, method chain like `ro.foo.bar` the
result of `ro.foo` is stored in `@result`, but cleared just
before `setup_message` and it seems GCed on specific machine.

```
  1) Error:
DRbTests::TestDRbCore#test_05_eq:
RangeError: "140" is recycled object
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:366:in `_id2ref'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:366:in `to_obj'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:1528:in `to_obj'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:1847:in `to_obj'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:620:in `recv_request'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:931:in `recv_request'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:1656:in `init_with_client'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:1668:in `setup_message'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:1632:in `perform'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:1725:in `block (2 levels) in main_loop'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:1721:in `loop'
    (druby://localhost:36141) /tmp/ruby/v3/src/trunk-repeat20-asserts/lib/drb/drb.rb:1721:in `block in main_loop'
    /tmp/ruby/v3/src/trunk-repeat20-asserts/test/drb/drbtest.rb:206:in `test_05_eq'
```

To prevent collecting, clear `@result` just after `setup_message`
and `setup_message` can get the last result object.
---
 lib/drb/drb.rb | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb
index 3e232139114..34970698bda 100644
--- a/lib/drb/drb.rb
+++ b/lib/drb/drb.rb
@@ -1627,9 +1627,12 @@ module DRb https://github.com/ruby/ruby/blob/trunk/lib/drb/drb.rb#L1627
       end
 
       def perform
-        @result = nil
-        @succ = false
-        setup_message
+        begin
+          setup_message
+        ensure
+          @result = nil
+          @succ = false
+        end
 
         if @block
           @result = perform_with_block
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]