Improve error handling for DeviceListener (#11484)

... particularly for when it races with a client shutdown.
This commit is contained in:
Richard van der Hoff 2023-08-30 10:35:15 +01:00 committed by GitHub
parent 50160b9969
commit 6cc42b7e2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 3 deletions

View file

@ -14,7 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixEvent, ClientEvent, EventType, MatrixClient, RoomStateEvent, SyncState } from "matrix-js-sdk/src/matrix";
import {
MatrixEvent,
ClientEvent,
EventType,
MatrixClient,
RoomStateEvent,
SyncState,
ClientStoppedError,
} from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
@ -260,7 +268,17 @@ export default class DeviceListener {
return cli?.getRooms().some((r) => cli.isRoomEncrypted(r.roomId)) ?? false;
}
private async recheck(): Promise<void> {
private recheck(): void {
this.doRecheck().catch((e) => {
if (e instanceof ClientStoppedError) {
// the client was stopped while recheck() was running. Nothing left to do.
} else {
logger.error("Error during `DeviceListener.recheck`", e);
}
});
}
private async doRecheck(): Promise<void> {
if (!this.running || !this.client) return; // we have been stopped
const cli = this.client;