Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cached statements hold strong references to bind values #141

Open
rwfranks opened this issue Oct 27, 2024 · 1 comment
Open

Cached statements hold strong references to bind values #141

rwfranks opened this issue Oct 27, 2024 · 1 comment

Comments

@rwfranks
Copy link

Transcribed verbatim from CPAN RT#82942, warts and all.

Thu Jan 24 21:17:01 2013 ribasushi [...] leporine.io - Ticket created
Subject: Cached statements hold strong references to bind values

Attached find a test demonstrating a contrived but real case of circular
reference leak. Clearing CachedKids makes the test pass, which made me
assume the problem is as noted in the subject.
Subject: dbi_bindval_leak.t

 use warnings;
 use strict;
 use Test::More;

 use DBI;
 use Scalar::Util 'weaken';

 {
  package _Stringifying::Structure;
  use overload '""' => sub { 42 };
 }

 my $weak_registry;

 {

  # the leak happens seemingly regardless of DBD used
  my $dbh = DBI->connect('dbi:SQLite::memory:', undef, undef, { AutoCommit => 1 });
  #my $dbh = DBI->connect(@ENV{map { "DBICTEST_MYSQL_$_" } qw(DSN USER PASS)}, { AutoCommit => 1 });

  my $sth = $dbh->prepare_cached('SELECT ?');

  # this is a simplified example - think of a deeply nested set of objects that
  # *happen* to link to something that holds a ref to the current $dbh
  my $bindval = bless {
    reference_to_dbh => $dbh,
  }, '_Stringifying::Structure';

  weaken ($weak_registry->{bindval} = $bindval);
  weaken ($weak_registry->{dbh} = $dbh);
  weaken ($weak_registry->{sth} = $sth);

  $sth->execute($bindval);
  is_deeply ($sth->fetchall_arrayref, [[ 42 ]], 'result brought back');

  # this would make tests pass
  #%{$dbh->{CachedKids}} = ();
 }

 for (sort keys %$weak_registry) {
  ok (!defined $weak_registry->{$_}, "No leaks of $_");
 }

 done_testing;
@rwfranks
Copy link
Author

Sat Jan 26 07:35:55 2013 TIMB [...] cpan.org - Correspondence added

Set to stalled currently per discussion at http://markmail.org/message/zpripshlx5fqpxoy

Sat Jan 26 07:35:58 2013 The RT System itself - Status changed from 'new' to 'open'

Sat Jan 26 07:35:58 2013 TIMB [...] cpan.org - Status changed from 'open' to 'stalled'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant