From 2752bc2b24d1e2c96c18b5f18372fc25e0ffc1fa Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 24 Jun 2019 23:29:37 +0000 Subject: msgmap: mid_insert: use plain "INSERT" to detect duplicates "INSERT OR IGNORE" still bumps the auto-increment counter in SQLite, which causes gaps to appear in NNTP article numbering. This bug appeared in v2 repos where V2Writable may call ->add repeatedly on the same message. This bug is apparent with public-inbox-watch and work-in-progress IMAP watchers which may rescan and (attempt to) reinsert the same message on mailbox changes. Most uses of public-inbox-mda were not affected, unless the same message is actually delivered multiple times to the mda. v1 is not affected, either, since deduplication is only based on Message-ID and msgmap never sees the duplicate. Reported-by: "Eric W. Biederman" --- lib/PublicInbox/Msgmap.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/Msgmap.pm') diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm index 0035c9e3..5a89b85a 100644 --- a/lib/PublicInbox/Msgmap.pm +++ b/lib/PublicInbox/Msgmap.pm @@ -126,9 +126,9 @@ sub mid_insert { my ($self, $mid) = @_; my $dbh = $self->{dbh}; my $sth = $dbh->prepare_cached(<<''); -INSERT OR IGNORE INTO msgmap (mid) VALUES (?) +INSERT INTO msgmap (mid) VALUES (?) - return if $sth->execute($mid) == 0; + return unless eval { $sth->execute($mid) }; my $num = $dbh->last_insert_id(undef, undef, 'msgmap', 'num'); $self->num_highwater($num) if defined($num); $num; -- cgit v1.2.3-24-ge0c7