Release the import locks in case of exception
MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -491,6 +491,7 @@ export default class TagService {
user: req.user
});
}
+ try {
// Default values for Tag import
const importedBy = req.user.id;
const importedOn = new Date();
@@ -555,6 +556,9 @@ export default class TagService {
}
// eslint-disable-next-line @typescript-eslint/no-misused-promises
}, async (error: CSVError) => {
+ // Release the lock
+ await LockingManager.release(importTagsLock);
+ // Log
await Logging.logError({
tenantID: req.user.tenantID,
module: MODULE_NAME, method: 'handleImportTags',
@@ -623,6 +627,9 @@ export default class TagService {
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
parser.on('error', async (error) => {
+ // Release the lock
+ await LockingManager.release(importTagsLock);
+ // Log
await Logging.logError({
tenantID: req.user.tenantID,
module: MODULE_NAME, method: 'handleImportTags',
@@ -638,6 +645,9 @@ export default class TagService {
});
file.pipe(parser);
} else {
+ // Release the lock
+ await LockingManager.release(importTagsLock);
+ // Log
await Logging.logError({
tenantID: req.user.tenantID,
module: MODULE_NAME, method: 'handleImportTags',
@@ -651,6 +661,11 @@ export default class TagService {
}
}
});
+ } catch (error) {
+ // Release the lock
+ await LockingManager.release(importTagsLock);
+ throw error;
+ }
}
private static async insertTags(tenantID: string, user: UserToken, action: ServerAction, tagsToBeImported: ImportedTag[], result: ActionsResponse): Promise<void> {

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -905,6 +905,7 @@ export default class UserService {
inSuccess: 0,
inError: 0
};
+ try {
// Delete all previously imported users
await UserStorage.deleteImportedUsers(req.user.tenantID);
// Get the stream
@@ -960,6 +961,9 @@ export default class UserService {
}
// eslint-disable-next-line @typescript-eslint/no-misused-promises
}, async (error: CSVError) => {
+ // Release the lock
+ await LockingManager.release(importUsersLock);
+ // Log
await Logging.logError({
tenantID: req.user.tenantID,
module: MODULE_NAME, method: 'handleImportUsers',
@@ -1028,6 +1032,9 @@ export default class UserService {
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
parser.on('error', async (error) => {
+ // Release the lock
+ await LockingManager.release(importUsersLock);
+ // Log
await Logging.logError({
tenantID: req.user.tenantID,
module: MODULE_NAME, method: 'handleImportUsers',
@@ -1043,6 +1050,9 @@ export default class UserService {
});
file.pipe(parser);
} else {
+ // Release the lock
+ await LockingManager.release(importUsersLock);
+ // Log
await Logging.logError({
tenantID: req.user.tenantID,
module: MODULE_NAME, method: 'handleImportUsers',
@@ -1056,6 +1066,11 @@ export default class UserService {
}
}
});
+ } catch (error) {
+ // Release the lock
+ await LockingManager.release(importUsersLock);
+ throw error;
+ }
}
public static async handleCreateUser(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {

Release the import locks in case of exception