I was hoping that untie %$ref in the topmost script would be the only relevant fault to explicate.

Digging down gets quite complex. dbme() doesn't do the tie itself, it merely determines a number of variable specs for the wanted kind of handle and calls an appropriate sub in the handle allocater module to supply it.

But there is something strange going on.

In the same module as dbme() is another sub metadbs() which with flag=1 returns a set of similar tied-hash-handles in a hash-of-refs for a standard set of db files, itself using dbme() for each handle in turn. The $copyfrom handle above is part of this set. When called with flag=0 right before the failing untie code above, metadbs() unties each of those handle-refs (including $copyfrom) and does not hang. And has been doing so in service to a number of topmost programs for a couple of years (apparently successfully).

use DBctrl qw(svhash); sub dbme { my ($dbtry, $makeyn, $hm) = @_; #.... $duplicates = 0; $bdbtype = 'HASH'; ($dbhand, $fail) = svhash($dbtry, $hm, $makeyn, $duplicates, $bdbtype); #..... return ($dbhand, $fail); }

and then digging deeper ... (difficult paste, sorry)

sub svhash { ($db, $hm, $makedb, $duplicates, $bdbtype) = @_; $makedb ||= 0; $duplicates ||= ''; $bdbtype ||= 'hash'; my %h; ($dbhandx, $fail) = ("", ""); $fail = _dbfix($db, $hm); unless ($fail) { my $bdb = BerkeleyDB::Hash; if (lc($bdbtype) =~ /btree/) { $bdb = BerkeleyDB::Btree;} my $fset = DB_CREATE; my $n = "0666"; my $dups = DB_DUP | DB_DUPSORT; $BerkeleyDB::Error = ''; if ($duplicates) { if ($makedb) { tie %h, $bdb, -Filename => $db, -Flags => $fset, + -Mode => $n, -Property => $dups + + or $fail = 1; } else { tie %h, $bdb, -Filename => $db, -Mode => $n, -Propert +y => $dups or $fail = 1; } } else { if ($makedb) { tie %h, $bdb, -Filename => $db, -Flags => $fset, + -Mode => $n or $fail = 1; } else { tie %h, $bdb, -Filename => $db, -Mode => $n + or $fail = 1; } } $fail = dbresult($fail, $BerkeleyDB::Error); unless ($fail) {$dbhandx = \%h;} } return ($dbhandx, $fail); }

In reply to Re^2: untie tied hash fails mysteriously by Pstack
in thread untie tied hash fails mysteriously by Pstack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.