]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
imap_searchqp: avoid occasional P::RD hint spew
authorEric Wong <e@80x24.org>
Fri, 14 Feb 2025 09:38:55 +0000 (09:38 +0000)
committerEric Wong <e@80x24.org>
Sat, 15 Feb 2025 07:05:04 +0000 (07:05 +0000)
It turns out Inline::C::Parser::RecDescent increments $::RD_HINT
when Inline::C rebuilds are necessary, thus causing verbose log
spew on bogus IMAP search queries in our own use of
Parse::RecDescent.  So, local-ize $::RD_HINT as we do with other
$::RD_* vars to avoid Inline::C influencing our IMAP query
parsing.

Triggering the increment of $::RD_HINT via
Inline::C::Parser::RecDescent may be achieved by forcing an
Inline::C rebuild, such as clearing the contents of
~/.cache/public-inbox/inline-c/* or
$ENV{PERL_INLINE_DIRECTORY}/* (but leaving one of those
top-level directories to trigger Inline::C rebuilds.  This bug
mainly manifested in t/imap_searchqp.t under the `make
check-run' test target which reuses existing processes to speed
up tests, though it could manifest in real-world -imapd (and
-netd) usage if the process spawning the daemon built Inline::C
code.

lib/PublicInbox/IMAPsearchqp.pm
t/imap_searchqp.t

index d1a943e53733c2c39dcb364590890e13d15d38fe..8136480ed7b43a5b194841309caa9f05c1322e62 100644 (file)
@@ -170,9 +170,6 @@ sub impossible {
        $$sql .= ' AND num < 0';
 }
 
-# XXX not sure suppessing RD_* is needed here, but t/imap_searchqp.t
-# sporadically fails
-local ($::RD_ERRORS, $::RD_WARN);
 my $prd = Parse::RecDescent->new(<<'EOG');
 <nocheck>
 { my $q = $PublicInbox::IMAPsearchqp::q; }
@@ -281,8 +278,8 @@ sub parse {
        my ($imap, $query) = @_;
        my $sql = '';
        %$q = (sql => \$sql, imap => $imap); # imap = PublicInbox::IMAP obj
-       # XXX not always effective for t/imap_searchqp.t
-       local ($::RD_ERRORS, $::RD_WARN);
+       # Inline::C::Parser::RecDescent may set RD_HINT
+       local ($::RD_ERRORS, $::RD_WARN, $::RD_HINT);
        my $res = eval { $prd->search_key(uc($query)) };
        return $@ if $@ && $@ =~ /\A(?:BAD|NO) /;
        return 'BAD unexpected result' if !$res || $res != $q;
index 95cdd2017a0cfca92c31dcb24625c38ce53a110a..13ee22346f090607ebb582057d26f32405dd7c41 100644 (file)
@@ -39,12 +39,7 @@ like($q, qr/\ANO \[/, 'bad charset rejected');
        open STDERR, '>&', $olderr;
        seek $tmperr, 0, SEEK_SET;
        read($tmperr, my $buf, -s $tmperr);
-       is($buf, '', 'nothing spewed to STDERR on bad query') or warn <<'EOM';
-FIXME: this sometimes fails despite setting $::RD_ERRORS + $::RD_WARN to
-undef in PublicInbox::IMAPsearchqp::parse and I don't understand why.
-It usually suceeds.  Let us know if you can help us understand this
-occasional failure at meta@public-inbox.org
-EOM
+       is $buf, '', 'nothing spewed to STDERR on bad query';
 }
 
 like($q, qr/\ABAD /, 'bad charset rejected');