From 6466b21e0776fdd88648730e7248d6887d380224 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 14 Nov 2019 01:12:11 +0000 Subject: inboxwritable: drop {-importer} cyclic reference InboxWritable caching the result of ->importer leads to a circular references with returned (V2Writable|Import) object holds onto the calling InboxWritable object. With public-inbox-watch, this leads to a memory leak if a user is reloading via SIGHUP after a message is imported (it would only become noticeable with SIGHUPs after every message imported). I would not expect anybody to to notice this in real-world usage. I only noticed this since I was making -xcpdb suitable for long-lived process use (e.g. "mod_perl style") and a flock remained unreleased on v1 inboxes after resharding. WatchMaildir (used by -watch) already handles caching of the importer object itself, and all of our other real-world uses of ->importer are short-lived or designed for batch scripts, so there's no need to cache the importer result internally. --- lib/PublicInbox/InboxWritable.pm | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'lib/PublicInbox/InboxWritable.pm') diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm index 9eab394d..c73910ac 100644 --- a/lib/PublicInbox/InboxWritable.pm +++ b/lib/PublicInbox/InboxWritable.pm @@ -52,22 +52,20 @@ sub init_inbox { sub importer { my ($self, $parallel) = @_; - $self->{-importer} ||= do { - my $v = $self->{version} || 1; - if ($v == 2) { - eval { require PublicInbox::V2Writable }; - die "v2 not supported: $@\n" if $@; - my $opt = $self->{-creat_opt}; - my $v2w = PublicInbox::V2Writable->new($self, $opt); - $v2w->{parallel} = $parallel; - $v2w; - } elsif ($v == 1) { - my @arg = (undef, undef, undef, $self); - PublicInbox::Import->new(@arg); - } else { - $! = 78; # EX_CONFIG 5.3.5 local configuration error - die "unsupported inbox version: $v\n"; - } + my $v = $self->{version} || 1; + if ($v == 2) { + eval { require PublicInbox::V2Writable }; + die "v2 not supported: $@\n" if $@; + my $opt = $self->{-creat_opt}; + my $v2w = PublicInbox::V2Writable->new($self, $opt); + $v2w->{parallel} = $parallel; + $v2w; + } elsif ($v == 1) { + my @arg = (undef, undef, undef, $self); + PublicInbox::Import->new(@arg); + } else { + $! = 78; # EX_CONFIG 5.3.5 local configuration error + die "unsupported inbox version: $v\n"; } } -- cgit v1.2.3-24-ge0c7