Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 7eb51a5

Browse files
authored
Merge pull request #111 from dhruvit-r/develop
fix: don't use expired token for gitlab client init
2 parents 04905d8 + 4729427 commit 7eb51a5

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

services/GitlabService.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class GitlabService {
9696
await svc.refreshAccessToken();
9797
svc.#gitlab = new Gitlab({
9898
host: config.GITLAB_API_BASE_URL,
99-
oauthToken: user.accessToken
99+
oauthToken: svc.#user.accessToken
100100
});
101101
return svc;
102102
} catch (err) {
@@ -123,10 +123,10 @@ class GitlabService {
123123
if (!lockedUser) {
124124
throw new Error(`Failed to acquire lock on user ${this.#user.id} after ${tries} attempts.`);
125125
}
126-
logger.debug(`[Lock ID: ${lockId}] Acquired lock on user ${this.#user.id}.`);
126+
logger.debug(`[Lock ID: ${lockId}] Acquired lock on user ${this.#user.username}.`);
127127
if (lockedUser.accessTokenExpiration && new Date().getTime() > lockedUser.accessTokenExpiration.getTime() -
128128
(config.GITLAB_REFRESH_TOKEN_BEFORE_EXPIRATION * MS_PER_SECOND)) {
129-
logger.debug(`[Lock ID: ${lockId}] Refreshing access token for user ${this.#user.id}.`);
129+
logger.debug(`[Lock ID: ${lockId}] Refreshing access token for user ${this.#user.username}.`);
130130
const query = {
131131
client_id: config.GITLAB_CLIENT_ID,
132132
client_secret: config.GITLAB_CLIENT_SECRET,
@@ -147,11 +147,10 @@ class GitlabService {
147147
_.assign(lockedUser, updates);
148148
await dbHelper.update(models.User, lockedUser.id, updates);
149149
}
150-
return lockedUser;
151150
} finally {
152151
if (lockedUser) {
153-
logger.debug(`[Lock ID: ${lockId}] Releasing lock on user ${this.#user.id}.`);
154-
await dbHelper.releaseLockOnUser(this.#user.id, lockId);
152+
logger.debug(`[Lock ID: ${lockId}] Releasing lock on user ${this.#user.username}.`);
153+
this.#user = await dbHelper.releaseLockOnUser(this.#user.id, lockId);
155154
}
156155
}
157156
}

utils/db-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,15 @@ async function acquireLockOnUser(userId, lockId, ttl) {
479479
* @returns {Promise<Object>} The lock object
480480
*/
481481
async function releaseLockOnUser(id, lockId) {
482-
const res = await models.User.update(
482+
const user = await models.User.update(
483483
{id},
484484
{lockId: null, lockExpiration: null},
485485
{
486486
condition: 'lockId = :lockId',
487487
conditionValues: {lockId}
488488
},
489489
);
490-
return res;
490+
return user;
491491
}
492492

493493
module.exports = {

0 commit comments

Comments
 (0)