fix(core): Detect DB connection aquisition deadlocks (no-changelog) (#9485)
Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
committed by
GitHub
parent
2fa46b6faa
commit
3094f1b886
@@ -17,8 +17,10 @@ export class ProjectRepository extends Repository<Project> {
|
||||
});
|
||||
}
|
||||
|
||||
async getPersonalProjectForUserOrFail(userId: string) {
|
||||
return await this.findOneOrFail({
|
||||
async getPersonalProjectForUserOrFail(userId: string, entityManager?: EntityManager) {
|
||||
const em = entityManager ?? this.manager;
|
||||
|
||||
return await em.findOneOrFail(Project, {
|
||||
where: { type: 'personal', projectRelations: { userId, role: 'project:personalOwner' } },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Container } from 'typedi';
|
||||
import type { EntitySubscriberInterface, UpdateEvent } from '@n8n/typeorm';
|
||||
import { EventSubscriber } from '@n8n/typeorm';
|
||||
import { User } from '../entities/User';
|
||||
import Container from 'typedi';
|
||||
import { ProjectRepository } from '../repositories/project.repository';
|
||||
import { ApplicationError, ErrorReporterProxy } from 'n8n-workflow';
|
||||
import { Logger } from '@/Logger';
|
||||
import { UserRepository } from '../repositories/user.repository';
|
||||
|
||||
import { Project } from '../entities/Project';
|
||||
import { User } from '../entities/User';
|
||||
import { UserRepository } from '../repositories/user.repository';
|
||||
|
||||
@EventSubscriber()
|
||||
export class UserSubscriber implements EntitySubscriberInterface<User> {
|
||||
@@ -27,14 +27,17 @@ export class UserSubscriber implements EntitySubscriberInterface<User> {
|
||||
fields.includes('email')
|
||||
) {
|
||||
const oldUser = event.databaseEntity;
|
||||
const name =
|
||||
const userEntity =
|
||||
newUserData instanceof User
|
||||
? newUserData.createPersonalProjectName()
|
||||
: Container.get(UserRepository).create(newUserData).createPersonalProjectName();
|
||||
? newUserData
|
||||
: Container.get(UserRepository).create(newUserData);
|
||||
|
||||
const project = await Container.get(ProjectRepository).getPersonalProjectForUser(
|
||||
oldUser.id,
|
||||
);
|
||||
const projectName = userEntity.createPersonalProjectName();
|
||||
|
||||
const project = await event.manager.findOneBy(Project, {
|
||||
type: 'personal',
|
||||
projectRelations: { userId: oldUser.id },
|
||||
});
|
||||
|
||||
if (!project) {
|
||||
// Since this is benign we're not throwing the exception. We don't
|
||||
@@ -47,7 +50,7 @@ export class UserSubscriber implements EntitySubscriberInterface<User> {
|
||||
return;
|
||||
}
|
||||
|
||||
project.name = name;
|
||||
project.name = projectName;
|
||||
|
||||
await event.manager.save(Project, project);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user