Merge pull request #6549 from alvasw/fix_mailbox_message_service_thread_leak_explosion

Fix MailboxMessageService thread leak/explosion
This commit is contained in:
Alejandro García 2023-02-03 15:15:39 +00:00 committed by GitHub
commit 8dbdecd6f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -430,15 +430,21 @@ public class MailboxMessageService implements HashMapChangedListener, PersistedD
// We run the batch processing of all mailbox messages we have received at startup in a thread to not block the UI. // We run the batch processing of all mailbox messages we have received at startup in a thread to not block the UI.
// For about 1000 messages decryption takes about 1 sec. // For about 1000 messages decryption takes about 1 sec.
private void threadedBatchProcessMailboxEntries(Collection<ProtectedMailboxStorageEntry> protectedMailboxStorageEntries) { private void threadedBatchProcessMailboxEntries(Collection<ProtectedMailboxStorageEntry> protectedMailboxStorageEntries) {
ListeningExecutorService executor = Utilities.getSingleThreadListeningExecutor("processMailboxEntry-" + new Random().nextInt(1000));
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
ListenableFuture<Set<MailboxItem>> future = executor.submit(() -> { SettableFuture<Set<MailboxItem>> future = SettableFuture.create();
var mailboxItems = getMailboxItems(protectedMailboxStorageEntries);
log.info("Batch processing of {} mailbox entries took {} ms", new Thread(() -> {
protectedMailboxStorageEntries.size(), try {
System.currentTimeMillis() - ts); var mailboxItems = getMailboxItems(protectedMailboxStorageEntries);
return mailboxItems; log.info("Batch processing of {} mailbox entries took {} ms",
}); protectedMailboxStorageEntries.size(),
System.currentTimeMillis() - ts);
future.set(mailboxItems);
} catch (Throwable throwable) {
future.setException(throwable);
}
}, "processMailboxEntry-" + new Random().nextInt(1000)).start();
Futures.addCallback(future, new FutureCallback<>() { Futures.addCallback(future, new FutureCallback<>() {
public void onSuccess(Set<MailboxItem> decryptedMailboxMessageWithEntries) { public void onSuccess(Set<MailboxItem> decryptedMailboxMessageWithEntries) {