ruby2.7: backport upstream fix to "hash modified during iteration"
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
ruby2.7 (Ubuntu) |
Invalid
|
Undecided
|
Unassigned | ||
Focal |
Fix Released
|
Medium
|
Lucas Kanashiro |
Bug Description
[Impact]
Ruby code cannot iterate over hashes while the garbage collector is started.
This was fixed upstream here:
https:/
https:/
[Test Plan]
$ lxc launch ubuntu-daily:focal ruby27-
$ lxc shell ruby27-
# apt update && apt upgrade -y && apt install -y ruby
# cat <<EOF >bug.rb
h = {a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8}
h.each{|k,v| GC.start; h.delete(k)}
EOF
# ruby bug.rb
Traceback (most recent call last):
1: from bug.rb:2:in `<main>'
bug.rb:2:in `each': ret: 2, hash modified during iteration (RuntimeError)
The error above should not happen.
[Where problems could occur]
This is a one line fix which should be straightforward, but if something happens it would be related to the .each method since the modification is there. Any unexpected behavior in .each might be related to this change.
[Original description]
I am using system-provided sonic-pi on Ubuntu 20.04. When stopping a loop, a thread terminates with exception:
#<Thread:
/usr/lib/
from /usr/lib/
from /usr/lib/
from /usr/lib/
This failure seems similar to one described here [1], which has been confirmed as a bug in Ruby [2]. The issue has received a one-line patch, which has been incorporated in Ruby v2.7.1.
[1] https:/
[2] https:/
Related branches
- git-ubuntu bot: Approve
- Bryce Harrington (community): Approve
- Canonical Server Reporter: Pending requested
-
Diff: 58 lines (+36/-0)3 files modifieddebian/changelog (+7/-0)
debian/patches/0026-reload-AR-table-body-for-transient-heap.patch (+28/-0)
debian/patches/series (+1/-0)
Changed in ruby2.7 (Ubuntu Focal): | |
assignee: | nobody → Lucas Kanashiro (lucaskanashiro) |
description: | updated |
tags: |
added: verification-done removed: verification-needed |
I have rebuilt Ruby after applying the upstream-provided patch and no longer have issues with sonic-pi.