Project

General

Profile

Actions

Bug #21882

closed

IO::Buffer#locked leaves the buffer locked when the block raises

Bug #21882: IO::Buffer#locked leaves the buffer locked when the block raises

Added by hanazuki (Kasumi Hanazuki) 7 days ago. Updated 2 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [x86_64-linux]
[ruby-core:124833]

Description

IO::Buffer#locked should unlock the buffer even after the block raises an exception.

buf = IO::Buffer.new(100)
buf.locked { fail } rescue nil
buf.locked { p :ok }  # expected to print :ok, but actually raises a LockedError

Updated by nobu (Nobuyoshi Nakada) 6 days ago Actions #2 [ruby-core:124836]

buf.locked {break} also leaves it locked.
Could you add a test for this case too?

Updated by hanazuki (Kasumi Hanazuki) 6 days ago Actions #3 [ruby-core:124837]

Thank you for your review, nobu. I added test cases for break and throw.

Updated by hanazuki (Kasumi Hanazuki) 2 days ago Actions #4

  • Status changed from Open to Closed

Applied in changeset git|b5ccab2093c9bb19ae8564a935e6fd72ec7354cc.


IO::Buffer#locked: Release lock even when the block raises (#16180)

IO::Buffer#locked: Release lock even when the block raises/breaks

Previously, IO::Buffer#locked leaks the lock when the block raises
an exception, or breaks.

Fixes: [Bug #21882]

Actions

Also available in: PDF Atom