Skip to content

Commit 92791c1

Browse files
authored
fix: Duplicate session destruction can cause unhandled promise rejection (#10319)
1 parent eea27af commit 92791c1

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

spec/ParseUser.spec.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,13 +1466,7 @@ describe('Parse.User testing', () => {
14661466
const user = await Parse.User.logInWith('facebook');
14671467
const sessionToken = user.getSessionToken();
14681468
const query = new Parse.Query('_Session');
1469-
// destroyDuplicatedSessions is fire-and-forget, poll until cleanup completes
1470-
let results;
1471-
for (let i = 0; i < 10; i++) {
1472-
results = await query.find({ useMasterKey: true });
1473-
if (results.length <= 1) { break; }
1474-
await new Promise(resolve => setTimeout(resolve, 100));
1475-
}
1469+
const results = await query.find({ useMasterKey: true });
14761470
expect(results.length).toBe(1);
14771471
expect(results[0].get('sessionToken')).toBe(sessionToken);
14781472
expect(results[0].get('createdWith')).toEqual({

src/RestWrite.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ RestWrite.prototype.destroyDuplicatedSessions = function () {
11401140
if (!user.objectId) {
11411141
return;
11421142
}
1143-
this.config.database.destroy(
1143+
return this.config.database.destroy(
11441144
'_Session',
11451145
{
11461146
user,
@@ -1149,7 +1149,11 @@ RestWrite.prototype.destroyDuplicatedSessions = function () {
11491149
},
11501150
{},
11511151
this.validSchemaController
1152-
);
1152+
).catch(e => {
1153+
if (e.code !== Parse.Error.OBJECT_NOT_FOUND) {
1154+
throw e;
1155+
}
1156+
});
11531157
};
11541158

11551159
// Handles any followup logic

0 commit comments

Comments
 (0)