Fix in-memory transactions in MessageReceiver

This commit is contained in:
Fedor Indutny 2021-05-20 16:49:08 -07:00 committed by Scott Nonnenberg
parent ceffc2380c
commit 7c07fdd589
2 changed files with 27 additions and 15 deletions

View File

@ -458,12 +458,15 @@ export class SignalProtocolStore extends EventsMixin {
async enqueueSenderKeyJob<T>(
encodedAddress: string,
task: () => Promise<T>
task: () => Promise<T>,
zone = GLOBAL_ZONE
): Promise<T> {
const senderId = await normalizeEncodedAddress(encodedAddress);
const queue = this._getSenderKeyQueue(senderId);
return this.withZone(zone, 'enqueueSenderKeyJob', async () => {
const senderId = await normalizeEncodedAddress(encodedAddress);
const queue = this._getSenderKeyQueue(senderId);
return queue.add<T>(task);
return queue.add<T>(task);
});
}
private _createSenderKeyQueue(): PQueue {
@ -567,12 +570,15 @@ export class SignalProtocolStore extends EventsMixin {
async enqueueSessionJob<T>(
encodedAddress: string,
task: () => Promise<T>
task: () => Promise<T>,
zone: Zone = GLOBAL_ZONE
): Promise<T> {
const id = await normalizeEncodedAddress(encodedAddress);
const queue = this._getSessionQueue(id);
return this.withZone(zone, 'enqueueSessionJob', async () => {
const id = await normalizeEncodedAddress(encodedAddress);
const queue = this._getSessionQueue(id);
return queue.add<T>(task);
return queue.add<T>(task);
});
}
private _createSessionQueue(): PQueue {

View File

@ -132,6 +132,7 @@ type DecryptedEnvelope = {
type LockedStores = {
readonly sessionStore: Sessions;
readonly identityKeyStore: IdentityKeys;
readonly zone?: Zone;
};
class MessageReceiverInner extends EventTarget {
@ -790,7 +791,7 @@ class MessageReceiverInner extends EventTarget {
items.map(async ({ data, envelope }) => {
try {
const plaintext = await this.queueEnvelope(
{ sessionStore, identityKeyStore },
{ sessionStore, identityKeyStore, zone },
envelope
);
if (plaintext) {
@ -1059,7 +1060,7 @@ class MessageReceiverInner extends EventTarget {
}
async decrypt(
{ sessionStore, identityKeyStore }: LockedStores,
{ sessionStore, identityKeyStore, zone }: LockedStores,
envelope: EnvelopeClass,
ciphertext: ByteBufferClass
): Promise<ArrayBuffer | null> {
@ -1112,7 +1113,8 @@ class MessageReceiverInner extends EventTarget {
ProtocolAddress.new(identifier, sourceDevice),
senderKeyStore,
messageBuffer
).then(plaintext => this.unpad(typedArrayToArrayBuffer(plaintext)))
).then(plaintext => this.unpad(typedArrayToArrayBuffer(plaintext))),
zone
);
} else if (envelope.type === envelopeTypeEnum.CIPHERTEXT) {
window.log.info('message from', this.getEnvelopeId(envelope));
@ -1139,7 +1141,8 @@ class MessageReceiverInner extends EventTarget {
ProtocolAddress.new(identifier, sourceDevice),
sessionStore,
identityKeyStore
).then(plaintext => this.unpad(typedArrayToArrayBuffer(plaintext)))
).then(plaintext => this.unpad(typedArrayToArrayBuffer(plaintext))),
zone
);
} else if (envelope.type === envelopeTypeEnum.PREKEY_BUNDLE) {
window.log.info('prekey message from', this.getEnvelopeId(envelope));
@ -1168,7 +1171,8 @@ class MessageReceiverInner extends EventTarget {
identityKeyStore,
preKeyStore,
signedPreKeyStore
).then(plaintext => this.unpad(typedArrayToArrayBuffer(plaintext)))
).then(plaintext => this.unpad(typedArrayToArrayBuffer(plaintext))),
zone
);
} else if (envelope.type === envelopeTypeEnum.UNIDENTIFIED_SENDER) {
window.log.info('received unidentified sender message');
@ -1241,7 +1245,8 @@ class MessageReceiverInner extends EventTarget {
),
senderKeyStore,
buffer
)
),
zone
);
}
@ -1261,7 +1266,8 @@ class MessageReceiverInner extends EventTarget {
identityKeyStore,
preKeyStore,
signedPreKeyStore
)
),
zone
);
};