diff --git a/app/sql_channel.js b/app/sql_channel.js index b74401313602..1bb631492f94 100644 --- a/app/sql_channel.js +++ b/app/sql_channel.js @@ -19,11 +19,11 @@ let singleQueue = null; let multipleQueue = null; function makeNewSingleQueue() { - singleQueue = new Queue({ concurrency: 1 }); + singleQueue = new Queue({ concurrency: 1, timeout: 1000 * 60 * 2 }); return singleQueue; } function makeNewMultipleQueue() { - multipleQueue = new Queue({ concurrency: 10 }); + multipleQueue = new Queue({ concurrency: 10, timeout: 1000 * 60 * 2 }); return multipleQueue; } diff --git a/js/background.js b/js/background.js index 9737bcf68755..5cf846dec827 100644 --- a/js/background.js +++ b/js/background.js @@ -14,9 +14,13 @@ // eslint-disable-next-line func-names (async function() { - const eventHandlerQueue = new window.PQueue({ concurrency: 1 }); + const eventHandlerQueue = new window.PQueue({ + concurrency: 1, + timeout: 1000 * 60 * 2, + }); Whisper.deliveryReceiptQueue = new window.PQueue({ concurrency: 1, + timeout: 1000 * 60 * 2, }); Whisper.deliveryReceiptQueue.pause(); Whisper.deliveryReceiptBatcher = window.Signal.Util.createBatcher({ diff --git a/js/logging.js b/js/logging.js index 0542fa856787..ff172c4e0528 100644 --- a/js/logging.js +++ b/js/logging.js @@ -142,7 +142,8 @@ window.onerror = (message, script, line, col, error) => { }; window.addEventListener('unhandledrejection', rejectionEvent => { - window.log.error( - `Top-level unhandled promise rejection: ${rejectionEvent.reason}` - ); + const error = rejectionEvent.reason; + const errorString = + error && error.stack ? error.stack : JSON.stringify(error); + window.log.error(`Top-level unhandled promise rejection: ${errorString}`); }); diff --git a/js/models/messages.js b/js/models/messages.js index cb384f27a3de..fae1fb5a5783 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -225,8 +225,9 @@ getPropsForSearchResult() { const sourceId = this.getContactId(); const from = this.findAndFormatContact(sourceId); - const convo = this.getConversation(); - const to = this.findAndFormatContact(convo.get('id')); + + const conversationId = this.get('conversationId'); + const to = this.findAndFormatContact(conversationId); return { from, @@ -235,7 +236,7 @@ isSelected: this.isSelected, id: this.id, - conversationId: this.get('conversationId'), + conversationId, sentAt: this.get('sent_at'), snippet: this.get('snippet'), }; diff --git a/js/modules/stickers.js b/js/modules/stickers.js index 94c914080eb1..e1173187736e 100644 --- a/js/modules/stickers.js +++ b/js/modules/stickers.js @@ -75,7 +75,7 @@ module.exports = { let initialState = null; let packsToDownload = null; -const downloadQueue = new Queue({ concurrency: 1 }); +const downloadQueue = new Queue({ concurrency: 1, timeout: 1000 * 60 * 2 }); async function load() { const [packs, recentStickers] = await Promise.all([ @@ -336,6 +336,7 @@ async function removeEphemeralPack(packId) { const paths = stickers.map(sticker => sticker.path); await pMap(paths, Signal.Migrations.deleteTempFile, { concurrency: 3, + timeout: 1000 * 60 * 2, }); // Remove it from database in case it made it there @@ -429,7 +430,10 @@ async function downloadEphemeralPack(packId, packKey) { await downloadStickerJob(coverProto); // Then the rest - await pMap(nonCoverStickers, downloadStickerJob, { concurrency: 3 }); + await pMap(nonCoverStickers, downloadStickerJob, { + concurrency: 3, + timeout: 1000 * 60 * 2, + }); } catch (error) { // Because the user could install this pack while we are still downloading this // ephemeral pack, we don't want to go change its status unless we're still in @@ -610,7 +614,10 @@ async function doDownloadStickerPack(packId, packKey, options = {}) { await downloadStickerJob(coverProto); // Then the rest - await pMap(nonCoverStickers, downloadStickerJob, { concurrency: 3 }); + await pMap(nonCoverStickers, downloadStickerJob, { + concurrency: 3, + timeout: 1000 * 60 * 2, + }); // Allow for the user marking this pack as installed in the middle of our download; // don't overwrite that status. @@ -724,6 +731,7 @@ async function deletePackReference(messageId, packId) { await pMap(paths, Signal.Migrations.deleteSticker, { concurrency: 3, + timeout: 1000 * 60 * 2, }); } @@ -743,5 +751,6 @@ async function deletePack(packId) { await pMap(paths, Signal.Migrations.deleteSticker, { concurrency: 3, + timeout: 1000 * 60 * 2, }); } diff --git a/libtextsecure/libsignal-protocol.js b/libtextsecure/libsignal-protocol.js index d6191e137054..c95d25cbdf6d 100644 --- a/libtextsecure/libsignal-protocol.js +++ b/libtextsecure/libsignal-protocol.js @@ -25175,7 +25175,7 @@ var jobQueue = {}; Internal.SessionLock.queueJobForNumber = function queueJobForNumber(number, runJob) { if (window.PQueue) { - jobQueue[number] = jobQueue[number] || new window.PQueue({ concurrency: 1 }); + jobQueue[number] = jobQueue[number] || new window.PQueue({ concurrency: 1, timeout: 1000 * 60 * 2 }); var queue = jobQueue[number]; return queue.add(runJob); } diff --git a/main.js b/main.js index 84122f1cdf6c..c80b378752cf 100644 --- a/main.js +++ b/main.js @@ -1433,7 +1433,7 @@ async function ensureFilePermissions(onlyFiles) { console.log(`Ensuring file permissions for ${files.length} files`); // Touch each file in a queue - const q = new PQueue({ concurrency: 5 }); + const q = new PQueue({ concurrency: 5, timeout: 1000 * 60 * 2 }); q.addAll( files.map(f => async () => { const isDir = f.endsWith('/'); diff --git a/scripts/generate-acknowledgments.js b/scripts/generate-acknowledgments.js index dbff0d11da4a..a8af237b2cea 100644 --- a/scripts/generate-acknowledgments.js +++ b/scripts/generate-acknowledgments.js @@ -83,7 +83,10 @@ async function main() { dependencyNames, getMarkdownForDependency, // Without this, we may run into "too many open files" errors. - { concurrency: 100 } + { + concurrency: 100, + timeout: 1000 * 60 * 2, + } ); const unformattedOutput = [ diff --git a/sticker-creator/components/StickerGrid.tsx b/sticker-creator/components/StickerGrid.tsx index d3bf7a81d5b5..33c2ec835bcc 100644 --- a/sticker-creator/components/StickerGrid.tsx +++ b/sticker-creator/components/StickerGrid.tsx @@ -11,7 +11,7 @@ import { stickersDuck } from '../store'; import { DropZone, Props as DropZoneProps } from '../elements/DropZone'; import { convertToWebp } from '../util/preload'; -const queue = new PQueue({ concurrency: 3 }); +const queue = new PQueue({ concurrency: 3, timeout: 1000 * 60 * 2 }); const SmartStickerFrame = SortableElement( ({ id, showGuide, mode }: StickerFrameProps) => { diff --git a/sticker-creator/preload.js b/sticker-creator/preload.js index 586a29b1a2bf..d84bfcaf5d3c 100644 --- a/sticker-creator/preload.js +++ b/sticker-creator/preload.js @@ -133,7 +133,10 @@ window.encryptAndUpload = async ( const encryptedStickers = await pMap( uniqueStickers, ({ webp }) => encrypt(webp.buffer, encryptionKey, iv), - { concurrency: 3 } + { + concurrency: 3, + timeout: 1000 * 60 * 2, + } ); const packId = await server.putStickers( diff --git a/ts/components/emoji/lib.ts b/ts/components/emoji/lib.ts index 5eefd6f5501a..99aae7f209c9 100644 --- a/ts/components/emoji/lib.ts +++ b/ts/components/emoji/lib.ts @@ -92,7 +92,7 @@ const makeImagePath = (src: string) => { return `${ROOT_PATH}node_modules/emoji-datasource-apple/img/apple/64/${src}`; }; -const imageQueue = new PQueue({ concurrency: 10 }); +const imageQueue = new PQueue({ concurrency: 10, timeout: 1000 * 60 * 2 }); const images = new Set(); export const preloadImages = async (): Promise => { diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index efbe069771ba..75a53d476baf 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -1347,7 +1347,11 @@ async function updateToSchemaVersion20( await instance.run('BEGIN TRANSACTION;'); try { - const migrationJobQueue = new PQueue({ concurrency: 10 }); + const migrationJobQueue = new PQueue({ + concurrency: 10, + timeout: 1000 * 60 * 5, + throwOnTimeout: true, + }); // The triggers on the messages table slow down this migration // significantly, so we drop them and recreate them later. // Drop triggers diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index bd850e5106f1..130060a5eaa1 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -147,9 +147,9 @@ class MessageReceiverInner extends EventTarget { 10 ); - this.incomingQueue = new PQueue({ concurrency: 1 }); - this.pendingQueue = new PQueue({ concurrency: 1 }); - this.appQueue = new PQueue({ concurrency: 1 }); + this.incomingQueue = new PQueue({ concurrency: 1, timeout: 1000 * 60 * 2 }); + this.pendingQueue = new PQueue({ concurrency: 1, timeout: 1000 * 60 * 2 }); + this.appQueue = new PQueue({ concurrency: 1, timeout: 1000 * 60 * 2 }); this.cacheAddBatcher = createBatcher({ wait: 200, diff --git a/ts/textsecure/WebAPI.ts b/ts/textsecure/WebAPI.ts index 2c60ac5d1a37..d836da510473 100644 --- a/ts/textsecure/WebAPI.ts +++ b/ts/textsecure/WebAPI.ts @@ -1677,7 +1677,7 @@ export function initialize({ }); // Upload stickers - const queue = new PQueue({ concurrency: 3 }); + const queue = new PQueue({ concurrency: 3, timeout: 1000 * 60 * 2 }); await Promise.all( stickers.map(async (sticker: ServerAttachmentType, index: number) => { const stickerParams = makePutParams( diff --git a/ts/util/batcher.ts b/ts/util/batcher.ts index 157c5a076dca..e005b261d18e 100644 --- a/ts/util/batcher.ts +++ b/ts/util/batcher.ts @@ -39,7 +39,7 @@ export function createBatcher( let batcher: BatcherType; let timeout: NodeJS.Timeout | null; let items: Array = []; - const queue = new PQueue({ concurrency: 1 }); + const queue = new PQueue({ concurrency: 1, timeout: 1000 * 60 * 2 }); function _kickBatchOff() { const itemsRef = items; diff --git a/ts/util/callingTones.ts b/ts/util/callingTones.ts index 131873df47e5..6bb992990415 100644 --- a/ts/util/callingTones.ts +++ b/ts/util/callingTones.ts @@ -1,7 +1,10 @@ import PQueue from 'p-queue'; import { Sound } from './Sound'; -const ringtoneEventQueue = new PQueue({ concurrency: 1 }); +const ringtoneEventQueue = new PQueue({ + concurrency: 1, + timeout: 1000 * 60 * 2, +}); class CallingTones { private ringtone?: Sound; diff --git a/ts/util/waitBatcher.ts b/ts/util/waitBatcher.ts index 64c250e7c32c..76ad7f97dbef 100644 --- a/ts/util/waitBatcher.ts +++ b/ts/util/waitBatcher.ts @@ -50,7 +50,7 @@ export function createWaitBatcher( let waitBatcher: BatcherType; let timeout: NodeJS.Timeout | null; let items: Array> = []; - const queue = new PQueue({ concurrency: 1 }); + const queue = new PQueue({ concurrency: 1, timeout: 1000 * 60 * 2 }); function _kickBatchOff() { const itemsRef = items;