From 58552f83130528a6faa5d67bde56436f68ea4ac8 Mon Sep 17 00:00:00 2001 From: Gero Posmyk-Leinemann Date: Fri, 29 Apr 2022 14:28:34 +0000 Subject: [PATCH 1/2] [server] Make account deletion for fault tolerant --- .../server/src/user/user-deletion-service.ts | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/components/server/src/user/user-deletion-service.ts b/components/server/src/user/user-deletion-service.ts index db6b11fe575a3e..453ac78041ca37 100644 --- a/components/server/src/user/user-deletion-service.ts +++ b/components/server/src/user/user-deletion-service.ts @@ -98,13 +98,37 @@ export class UserDeletionService { const runningWorkspaces = await this.workspaceDb.findRunningInstancesWithWorkspaces(undefined, user.id); await Promise.all( - runningWorkspaces.map(async (wsi) => { + runningWorkspaces.map(async (info) => { + const wsi = info.latestInstance; + const req = new StopWorkspaceRequest(); - req.setId(wsi.latestInstance.id); + req.setId(wsi.id); req.setPolicy(StopWorkspacePolicy.NORMALLY); - const manager = await this.workspaceManagerClientProvider.get(wsi.latestInstance.region); - await manager.stopWorkspace({}, req); + try { + const manager = await this.workspaceManagerClientProvider.get(wsi.region); + await manager.stopWorkspace({}, req); + } catch (err) { + log.debug( + { + userId: info.workspace.ownerId, + workspaceId: info.workspace.id, + instanceId: wsi.id, + }, + "Unable to stop workspace on account deletion", + err, + ); + + // We cannot find a workspace manager client for this instances' region, or there is any other error while stopping that workspace properly. + // This might be the case if the workspace cluster which we try to stop an instance on is no longer registered. + // This is bad state, but might happen anyway. Instead of failing, we mark the workspace instance as stopped. + await this.workspaceDb.updateInstancePartial(wsi.id, { + status: { + ...wsi.status, + phase: "stopped", + }, + }); + } }), ); } From dd2ea93e38ba6b19346a5e7ffe2ae4575cf155cc Mon Sep 17 00:00:00 2001 From: Gero Posmyk-Leinemann Date: Fri, 29 Apr 2022 15:00:37 +0000 Subject: [PATCH 2/2] [server] Fix workspace anonymization --- components/server/src/user/user-deletion-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/server/src/user/user-deletion-service.ts b/components/server/src/user/user-deletion-service.ts index 453ac78041ca37..150de6c3f7abfe 100644 --- a/components/server/src/user/user-deletion-service.ts +++ b/components/server/src/user/user-deletion-service.ts @@ -154,7 +154,7 @@ export class UserDeletionService { const workspaces = await this.workspaceDb.findWorkspacesByUser(userId); await Promise.all( - workspaces.map((ws) => async () => { + workspaces.map(async (ws) => { this.anonymizeWorkspace(ws); await this.workspaceDb.store(ws); }),