]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
msgmap: mid_insert: reraise on unexpected errors
authorEric Wong <e@80x24.org>
Fri, 26 Jul 2024 21:31:09 +0000 (21:31 +0000)
committerEric Wong <e@80x24.org>
Tue, 30 Jul 2024 23:26:22 +0000 (23:26 +0000)
SQLITE_CONSTRAINT is the only SQLite error we really expect under
normal circumstances.  This avoids infinite loops when writing
to inboxes after hitting ENOSPC.

Reported-by: Robin H. Johnson <robbat2@orbis-terrarum.net>
Link: https://public-inbox.org/git/robbat2-20240722T060013-765939809Z@orbis-terrarum.net/
lib/PublicInbox/Msgmap.pm
t/msgmap.t
t/v2writable.t

index cb4bb2956ba2e6f856596a7dffccf7d6a888b34b..c4bc766d2395387ca49d99844ab53c450849b9f2 100644 (file)
@@ -12,6 +12,7 @@ use strict;
 use v5.10.1;
 use DBI;
 use DBD::SQLite;
+use DBD::SQLite::Constants qw(SQLITE_CONSTRAINT);
 use PublicInbox::Over;
 use Scalar::Util qw(blessed);
 
@@ -113,7 +114,10 @@ sub mid_insert {
        my $sth = $self->{dbh}->prepare_cached(<<'');
 INSERT INTO msgmap (mid) VALUES (?)
 
-       return unless eval { $sth->execute($mid) };
+       unless (eval { $sth->execute($mid) }) {
+               return if $self->{dbh}->err == SQLITE_CONSTRAINT;
+               die $@;
+       }
        my $num = $self->{dbh}->last_insert_id(undef, undef, 'msgmap', 'num');
        $self->num_highwater($num) if defined($num);
        $num;
index 124d3b103cdc981b88a2af0076573dddc1d47af4..fb9c2d93321e901d1d4acbd30c0ad16360c50d26 100644 (file)
@@ -3,6 +3,9 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use v5.12;
 use PublicInbox::TestCommon;
+use autodie;
+use Config;
+use PublicInbox::Spawn qw(popen_rd);
 require_mods('DBD::SQLite');
 use_ok 'PublicInbox::Msgmap';
 my ($tmpdir, $for_destroy) = tmpdir();
@@ -70,4 +73,17 @@ is(eval {
        'ok'
 }, 'ok', 'atfork_* work on tmp_clone');
 
-done_testing();
+SKIP: {
+       my $strace = strace_inject;
+       open my $fh, '>', my $trace = "$tmpdir/trace.out";
+       my $rd = popen_rd([ $strace, '-p', $$, '-o', $trace,
+               '-e', 'inject=pwrite64:error=ENOSPC'], undef, { 2 => 1 });
+       $rd->poll_in(10) or die 'strace not ready';
+       is eval { $d->mid_insert('this-better-trigger-ENOSPC@error') },
+               undef, 'insert fails w/ ENOSPC';
+       like $@, qr/ disk is full/, '$@ reports ENOSPC';
+       kill 'TERM', $rd->attached_pid;
+       $rd->close;
+}
+
+done_testing;
index 1b7e9e7d3c3d73b279f1e7dccc47d80eb2dfa90b..a062d1b3a0cc53a57bea3d71527092c8f3f1d614 100644 (file)
@@ -6,6 +6,8 @@ use Test::More;
 use PublicInbox::Eml;
 use PublicInbox::ContentHash qw(content_digest content_hash);
 use PublicInbox::TestCommon;
+use PublicInbox::Spawn qw(popen_rd);
+use Config;
 use Cwd qw(abs_path);
 require_git(2.6);
 require_mods(qw(DBD::SQLite Xapian));
@@ -335,4 +337,18 @@ ok($@, 'V2Writable fails on non-existent dir');
        is($mode, 0664, sprintf('0%03o', $mode).' is 0664');
 }
 
-done_testing();
+SKIP: {
+       my $strace = strace_inject;
+       my $eml = eml_load 't/plack-qp.eml';
+       open my $fh, '>', my $trace = "$inboxdir/trace.out";
+       my $rd = popen_rd([ $strace, '-p', $$, '-o', $trace,
+               '-e', 'inject=pwrite64:error=ENOSPC'], undef, { 2 => 1 });
+       $rd->poll_in(10) or die 'strace not ready';
+       ok ! eval { $im->add($eml) }, 'v2w->add fails on ENOSPC';
+       like $@, qr/ disk is full/, 'set $@ for ENOSPC';
+       $im->done;
+       kill 'TERM', $rd->attached_pid;
+       $rd->close;
+}
+
+done_testing;