[#102652] [Ruby master Bug#17664] Behavior of sockets changed in Ruby 3.0 to non-blocking — ciconia@...
Issue #17664 has been reported by ciconia (Sharon Rosner).
23 messages
2021/02/28
[ruby-core:102343] [Ruby master Bug#17488] Regression in Ruby 3: Hash#key? is non-deterministic when argument uses DelegateClass
From:
naruse@...
Date:
2021-02-01 09:22:29 UTC
List:
ruby-core #102343
Issue #17488 has been updated by naruse (Yui NARUSE).
Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONE
ruby_3_0 b2beb8586e930c168af434d6545f75d76123192b.
----------------------------------------
Bug #17488: Regression in Ruby 3: Hash#key? is non-deterministic when argument uses DelegateClass
https://bugs.ruby-lang.org/issues/17488#change-90203
* Author: myronmarston (Myron Marston)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
* Backport: 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONE
----------------------------------------
Upon upgrading a library to run on Ruby 3.0, I have observed that `Hash#key?` has non-deterministic behavior when the argument uses `DelegateClass`. This non-deterministic behavior was not present in Ruby 2.7.
Reproducing this is slightly difficult; the behavior appears to be deterministic (but not necessarily correct) within a single ruby process. To reproduce the non-determinism, you need to start ruby many times to observe different results. My script below does this.
## Reproduction script
``` ruby
puts "Running on Ruby: #{RUBY_DESCRIPTION}"
program = <<~EOS
require "delegate"
TypeName = DelegateClass(String)
hash = {
"Int" => true,
"Float" => true,
"String" => true,
"Boolean" => true,
"WidgetFilter" => true,
"WidgetAggregation" => true,
"WidgetEdge" => true,
"WidgetSortOrder" => true,
"WidgetGrouping" => true,
}
puts hash.key?(TypeName.new("WidgetAggregation"))
EOS
iterations = 20
results = iterations.times.map { `ruby -e '#{program}'`.chomp }.tally
puts "Results of checking `Hash#key?` #{iterations} times: #{results.inspect}"
```
Put this in a file like `ruby3_hash_bug.rb`, and run it using either Ruby 2.7 (to see `Hash#key?` consistently return `true`) or Ruby 3.0 (to see `Hash#key?` produce non-deterministic behavior).
## Ruby 2.7 results
```
Running on Ruby: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
Results of checking `Hash#key?` 20 times: {"true"=>20}
```
## Ruby 3.0 results
```
Running on Ruby: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
Results of checking `Hash#key?` 20 times: {"true"=>12, "false"=>8}
```
Note that the ratio of `true` to `false` is non-deterministic; here are a couple other runs on Ruby 3.0 with different results:
```
Running on Ruby: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
Results of checking `Hash#key?` 20 times: {"false"=>7, "true"=>13}
```
```
Running on Ruby: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
Results of checking `Hash#key?` 20 times: {"true"=>11, "false"=>9}
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>