Matrix: avoid shutdown races in decrypt drain

This commit is contained in:
Gustavo Madeira Santana
2026-03-20 12:06:02 -07:00
parent 8fcd0384fa
commit 10d9770aa6
3 changed files with 11 additions and 1 deletions

View File

@@ -327,6 +327,9 @@ describe("monitorMatrixProvider", () => {
hoisted.client.drainPendingDecryptions.mockImplementation(async () => {
hoisted.callOrder.push("drain-decrypts");
});
hoisted.stopThreadBindingManager.mockImplementation(() => {
hoisted.callOrder.push("stop-manager");
});
hoisted.releaseSharedClientInstance.mockImplementation(async () => {
hoisted.callOrder.push("release-client");
return true;
@@ -365,6 +368,9 @@ describe("monitorMatrixProvider", () => {
hoisted.callOrder.indexOf("handler-done"),
);
expect(hoisted.callOrder.indexOf("handler-done")).toBeLessThan(
hoisted.callOrder.indexOf("stop-manager"),
);
expect(hoisted.callOrder.indexOf("stop-manager")).toBeLessThan(
hoisted.callOrder.indexOf("stop-deduper"),
);
expect(hoisted.callOrder.indexOf("stop-deduper")).toBeLessThan(

View File

@@ -153,10 +153,10 @@ export async function monitorMatrixProvider(opts: MonitorMatrixOpts = {}): Promi
}
cleanedUp = true;
try {
threadBindingManager?.stop();
client.stopSyncWithoutPersist();
await client.drainPendingDecryptions("matrix monitor shutdown");
await waitForInFlightRoomMessages();
threadBindingManager?.stop();
await inboundDeduper.stop();
await releaseSharedClientInstance(client, "persist");
} finally {

View File

@@ -337,6 +337,10 @@ export class MatrixDecryptBridge<TRawEvent extends DecryptBridgeRawEvent> {
}
await new Promise<void>((resolve) => {
this.retryIdleResolvers.add(resolve);
if (this.activeRetryRuns === 0) {
this.retryIdleResolvers.delete(resolve);
resolve();
}
});
}