Skip to content

Commit 3461621

Browse files
committed
[server] fix reusing soft-deleted identities
1 parent 7ecc196 commit 3461621

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

components/gitpod-db/src/periodic-deleter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class PeriodicDbDeleter {
6565
for (const i in rows) {
6666
const row = rows[i];
6767
const whereClause = whereClauseFn(row);
68-
deletions.push(`DELETE FROM ${table.name} WHERE ${whereClause};`);
68+
deletions.push(`DELETE FROM ${table.name} WHERE ${whereClause} AND ${deletionColumn} = true;`);
6969
}
7070

7171
return result;

components/server/src/user/user-service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ export class UserService {
137137
if (userUpdate) {
138138
userUpdate(newUser);
139139
}
140-
newUser.identities.push(identity);
140+
// HINT: we need to specify `deleted: false` here, so that any attempt to reuse the same
141+
// entry would converge to a valid state. The identities are identified by the external
142+
// `authId`, and if accounts are deleted, such entries are soft-deleted until the periodic
143+
// deleter will take care of them. Reuse of soft-deleted entries would lead to an invalid
144+
// state. This measure of prevention is considered in the period deleter as well.
145+
newUser.identities.push({ ...identity, deleted: false });
141146
this.handleNewUser(newUser, isFirstUser);
142147
newUser = await this.userDb.storeUser(newUser);
143148
if (token) {

0 commit comments

Comments
 (0)