Skip to content

Images::Image.open discards its block and has no known reference — the Augeas half was never blocked, see #952 #950

Closed

Description

@tannevaled

Two open class methods take a block and discard it, found by the derived
open-door ratchet added alongside this issue (TestEveryOpenDoorIsAccountedFor).
Both are binding surfaces, not MRI core, which is why nothing had asked.

Measured: the code ignores the block

site signature what it does with a block
internal/vm/augeas.go:71 (Augeas.open, and Augeas.create — the same open func) func(_ *VM, _ object.Value, args []object.Value, _ *Proc) nothing: the parameter is _
internal/vm/images.go:93 (Images::Image.open) func(vm *VM, _ object.Value, args []object.Value, _ *Proc) nothing: the parameter is _

Klass.open(…) { |x| … } therefore returns the handle, never runs the block, and
closes nothing — which is the shape that cost #916 its 27 hung library/net-http
files, and the shape #931 and #939 chased through the socket family. The other
seven inline open handlers in the package were read one by one in the same pass
and all honour their block (Dir, File, IO, StringIO, Net::FTP,
SQLite3::Database, bbolt), as do the six socket doors and Resolv::DNS once
#948's sibling fix lands.

⛔ What is NOT measured, and it is the whole decision

Whether the reference gems have a block form at all. Neither is installed on
the machine this was found on, so this is a reading of rbgo's source and nothing
else. Discarding a block is only a defect if the reference accepts one:

  • ruby-augeas (hercules-team/ruby-augeas): Augeas.create is documented as
    yielding the handle and closing it when a block is given, and Augeas.open is
    its alias — but that is recalled, not read, and recalling a library's
    contract instead of citing its source is the mistake this repository keeps
    paying for. It needs the gem's lib/augeas.rb in front of someone.
  • Images::Image.open has no obvious upstream: the API is modelled on this
    org's own go-images, and ruby-vips / MiniMagick spell the same operation
    Vips::Image.new_from_file / MiniMagick::Image.open, neither of which yields.
    So no block form may be correct here, and the fix would be to document that
    rather than to add one.

What settles it

For each of the two, read the reference's own source and quote it:

gem contents augeas            # then read lib/augeas.rb's self.create

Then either route the site through socketOpenWithBlock(cls, <the new fn>) — the
helper already in socket.go, which yields, closes through the class's own
#close and answers the block's value — or record in
internal/vm/testdata/open-doors.txt that the reference has no block form, with
the citation.

⚠ If socketOpenWithBlock is used, check the class's #close first: it closes
through that method, so a #close that raises turns every block form into that
exception. That is exactly what Resolv::DNS needed fixing for in the sibling
change — its #close was on the NotImplementedError list.

Refs #931, #939, #916, #948

🤖 Generated with Claude Code

Prior art: priorart "Augeas.open and Images::Image.open discard the block they are given" at 2026-11-15 22:42 CET reported prior art; checked: priorart at 22:42 returned 776 entries, none about these two sites: #931 is TCPSocket.open (sockets), #939 (merged) fixed three socket doors and FILED the fourth (Resolv::DNS) which the sibling change fixes, #916 is the hang count those caused. The augeas hits are all Renovate dependency PRs. No entry covers a binding surface discarding its block outside the socket family.

Activity

  1. tannevaled commented on Nov 15, 2026

    @tannevaled
    ContributorAuthor

    The references are read. One half is settled, the other is not — and they must stop being treated alike

    I filed this saying the reference contract was unverified and naming the command
    that would settle it. That was 20 minutes of reading away, so here it is.

    ⛔ Augeas.open is a CONFIRMED defect

    hercules-team/ruby-augeas, lib/augeas.rb, read at
    https://raw.githubusercontent.com/hercules-team/ruby-augeas/master/lib/augeas.rb:

    def self.open(root = nil, loadpath = nil, flags = NONE, &block)
        aug = open3(root, loadpath, flags)
        if block_given?
            begin
                rv = yield aug
                return rv
            ensure
                aug.close
            end
        else
            return aug
        end
    end

    block_given?, yield aug, the block's value returned, aug.close in an
    ensure. That is socketOpenWithBlock's contract to the letter — and the same
    parameter list rbgo already has
    (root, loadpath, flags). So this is not a
    question any more.

    ⛔ But the fix is TWO parts, which is why #951 did not make it one

    rbgo's Augeas has no #close at all. git grep close internal/vm/augeas.go
    is empty. Consequences:

    1. socketOpenWithBlock closes through cls.methods["close"] and skips it when
      absent, so routing open through the helper today would yield and return the
      block's value but close nothing — a block form that looks right and leaks
      the handle.
    2. aug.close written by hand in Ruby is a NoMethodError, which ruby-augeas
      users have no reason to expect.

    So #close comes first, and it needs go-augeas's handle API read — whether
    augeas.Open's value has a Close, and whether closing twice is safe, since the
    helper's close must be idempotent. That is its own change, not a line in a test
    PR.

    ⚠ A second divergence the same reading turned up, and I have NOT verified it

    ruby-augeas's create is not the same method as open:

    def self.create(opts={}, &block)
      Augeas::Facade::create(opts, &block)
    end

    An options hash, not (root, loadpath, flags) — and it delegates to
    Augeas::Facade::create in lib/augeas/facade.rb, which I did not fetch.
    rbgo registers create and open as literally the same func
    (augeas.go:77-78), with the positional signature. Whether MRI's create
    accepts the positional form at all is unread, so this is a lead, not a finding.
    The doc comment says create's block form closes too, but a doc comment is a dated
    claim like any other.

    Images::Image.open moves the OTHER way: unspecified, not a defect

    go-ruby-images' README
    (https://raw.githubusercontent.com/go-ruby-images/images/main/README.md, HTTP
    200) documents no Ruby Image.open and no block form at all. It documents the
    Go library — images.Open("photo.jpg"), a package-level call returning an image —
    and the img.Open(2) it does show is a morphological opening, not a file opener.
    ruby-vips and MiniMagick spell this operation without a block
    (Vips::Image.new_from_file, MiniMagick::Image.open), neither yielding.

    So there is no evidence of a gap here, and quite possibly nothing to fix: the
    work is to document that Images::Image.open takes no block, or to find the
    binding's actual reference, which the README is not.

    What this issue is now

    • Augeas: blocked on #close, which is a real small change. Not a question.
    • Images: still a question, and a different one than I filed — not "does the
      gem yield?" but "what is this binding's reference at all?".

    internal/vm/testdata/open-doors.txt in #951 carries both rows with that
    distinction written into them, so the next reader does not have to guess which
    kind of unknown each one is.

    Refs #951, #931, #939

    🤖 Generated with Claude Code

  2. changed the title [-]Augeas.open and Images::Image.open discard the block they are given, and the reference contract is unverified[/-] [+]Augeas.open discards its block: confirmed against ruby-augeas, blocked on a missing #close — and Images::Image.open has no known reference[/+] on Nov 15, 2026
  3. tannevaled commented on Nov 16, 2026

    @tannevaled
    ContributorAuthor

    Correcting this issue: the Augeas half was never blocked

    This issue, and the testdata/open-doors.txt row behind it, said the Augeas half could not be fixed:

    NOT fixed here because it is TWO parts: rbgo's Augeas has no #close method at all, so the helper would yield without closing and aug.close in Ruby is a NoMethodError.

    Both sentences are true. The conclusion drawn from them is not. I asked what #close frees — and go-ruby-augeas's handle indeed exposes no Close — when the question is what #close makes observable. From ext/augeas/_augeas.c, now read:

    VALUE augeas_close (VALUE s) {
        augeas *aug = aug_handle(s);
        aug_close(aug);
        DATA_PTR(s) = NULL;
        return Qnil;
    }
    
    /* aug_handle, which EVERY method calls first */
    if (aug == NULL) {
        rb_raise(rb_eSystemCallError, "Failed to retrieve connection");
    }

    #close answers nil and poisons the object; afterwards every method raises SystemCallError, a second #close included, because aug_handle runs before aug_close. In an in-memory tree there is nothing to free, so that is a flag plus a guard — and the guard has exactly one site, the self accessor all seventeen instance methods already go through. Nothing was needed from the dependency.

    #952 does it, and the block form with it.

    A third divergence, which reading the reference turned up

    create and open were the same positional native. The gem's are different functions:

    lib/augeas.rb:  def self.open(root = nil, loadpath = nil, flags = NONE, &block)
    lib/augeas.rb:  def self.create(opts={}, &block)   # -> Augeas::Facade::create

    Augeas.create takes an options hash, and three properties of facade.rb's single opts.each_key pass are observable: a flag is armed by its key's presence and not its value, so create(type_check: false) sets TYPE_CHECK; :root/:loadpath are excluded by a condition rather than removed; and validation and assembly share one pass, so the first offending key raises and the error depends on the caller's insertion order. All three are pinned in #952.

    ⛔ Augeas.create("/root", "/lens", 5) was accepted before and is now a TypeError — breaking for this binding, so a MINOR bump below v1.

    What stays open here

    The Images::Image.open half only. It discards its block too, but it is not a known defect: go-ruby-images documents no Ruby Image.open and no block form at all — it documents the Go library (images.Open("photo.jpg")) — and ruby-vips and MiniMagick both spell this operation without a block. What that half needs is a reference, not a patch. Until one is identified, "no block form" may be the contract to document rather than a gap to fill.

    And the gate that should have caught this was blind to it

    TestEveryOpenDoorIsAccountedFor (#951) marked every derived door as seen, socketOpenWithBlock ones included, and called a table row stale only when no door carried its key — asking "does this door still exist?" instead of "does this door still need a row?". So fixing Augeas.open moved nothing: the test stayed green with the row still reading ⛔ CONFIRMED DEFECT about a repaired door.

    It was found by changing the code the gate watches and noticing the gate did not move, not by re-reading the gate. #952 pulls the verdict out into a pure function with its own seven-case control, one case being "a door FIXED into socketOpenWithBlock leaves its row stale".

    🤖 Generated with Claude Code

  4. changed the title [-]Augeas.open discards its block: confirmed against ruby-augeas, blocked on a missing #close — and Images::Image.open has no known reference[/-] [+]Images::Image.open discards its block and has no known reference — the Augeas half was never blocked, see #952[/+] on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions