From dfe331c14a023beada3d4cb36b19f00fde6979f3 Mon Sep 17 00:00:00 2001 From: dholms Date: Mon, 20 Nov 2023 13:26:08 -0600 Subject: [PATCH] better cleanup of actor-stores --- packages/common-web/src/async.ts | 6 +++++- packages/pds/src/api/com/atproto/server/createAccount.ts | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/common-web/src/async.ts b/packages/common-web/src/async.ts index bed78552969..e6da0fa6200 100644 --- a/packages/common-web/src/async.ts +++ b/packages/common-web/src/async.ts @@ -111,7 +111,11 @@ export class AsyncBuffer { async *events(): AsyncGenerator { while (true) { if (this.closed && this.buffer.length === 0) { - return + if (this.toThrow) { + throw this.toThrow + } else { + return + } } await this.promise if (this.toThrow) { diff --git a/packages/pds/src/api/com/atproto/server/createAccount.ts b/packages/pds/src/api/com/atproto/server/createAccount.ts index 6f8ae91146a..adfdab3b0f8 100644 --- a/packages/pds/src/api/com/atproto/server/createAccount.ts +++ b/packages/pds/src/api/com/atproto/server/createAccount.ts @@ -27,9 +27,8 @@ export default function (server: Server, ctx: AppContext) { let didDoc: DidDocument | undefined let creds: { accessJwt: string; refreshJwt: string } + await ctx.actorStore.create(did, signingKey) try { - await ctx.actorStore.create(did, signingKey) - await ctx.actorStore.clearReservedKeypair(signingKey.did(), did) const commit = await ctx.actorStore.transact(did, (actorTxn) => actorTxn.repo.createRepo([]), ) @@ -60,7 +59,9 @@ export default function (server: Server, ctx: AppContext) { await ctx.sequencer.sequenceCommit(did, commit, []) await ctx.accountManager.updateRepoRoot(did, commit.cid, commit.rev) didDoc = await didDocForSession(ctx, did, true) + await ctx.actorStore.clearReservedKeypair(signingKey.did(), did) } catch (err) { + // this will only be reached if the actor store _did not_ exist before await ctx.actorStore.destroy(did) throw err }