Fix deadlock in saveIdentity

This commit is contained in:
Fedor Indutny 2023-10-05 02:39:09 +02:00 committed by GitHub
parent 68185606e7
commit 8172840535
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 229 additions and 160 deletions

View file

@ -20,6 +20,7 @@ import { v4 as generateUuid } from 'uuid';
import { signal } from '../protobuf/compiled';
import { sessionStructureToBytes } from '../util/sessionTranslation';
import * as durations from '../util/durations';
import { explodePromise } from '../util/explodePromise';
import { Zone } from '../util/Zone';
import * as Bytes from '../Bytes';
@ -262,6 +263,29 @@ describe('SignalProtocolStore', () => {
await store.saveIdentity(identifier, testKey.pubKey);
await store.saveIdentity(identifier, newIdentity);
});
it('should not deadlock', async () => {
const newIdentity = getPublicKey();
const zone = new Zone('zone', {
pendingSenderKeys: true,
pendingSessions: true,
pendingUnprocessed: true,
});
await store.saveIdentity(identifier, testKey.pubKey);
const { promise, resolve } = explodePromise<void>();
await Promise.all([
store.withZone(zone, 'test', async () => {
await promise;
return store.saveIdentity(identifier, newIdentity, false, { zone });
}),
store.saveIdentity(identifier, newIdentity, false, {
zone: GLOBAL_ZONE,
}),
resolve(),
]);
});
describe('When there is no existing key (first use)', () => {
before(async () => {