Missing database entries under heavy load

If my server is under heavy load with many concurrent requests, inserts sometimes pretend to save a new object to the databse, return the DBO (which look correct), but then selecting that same entries returns nothing? export async function insertProject(projectDto: InsertProject, userId: number) { const formFiles = projectDto.addFiles; try { if (!isModuleEnabled('projectCustomFields')) projectDto.isMeasurementApproved = true; const dbos = await db .insert(projects) .values({ ...projectDto, updatedBy: userId }) .returning(); const dbo = dbos[0]; await updateProjectDependencies(dbo.id, projectDto); const projectJobs = await db.select().from(jobs).where(eq(jobs.projectId, dbo.id)); await setJobUsers(projectJobs, dbo, projectDto.measurementUsers ?? []); if (projectDto.changeNote) await insertProjectChangeNote(userId, dbo.id, projectDto.changeNote); await insertFiles(formFiles, dbo.id, 'projects', 'project'); sendEventTo('projects'); await insertProjectHistory(userId, 'project:create', dbo); await recalculateProjectStartAndEndDates(dbo.id); const test = await db.select().from(projects).where(eq(projects.id, dbo.id)); console.log('Inserted project with ID: ', dbo.id, dbos.length); console.log('🚀 ~ insertProject ~ test:', dbo.id, test.length); return dbo; } catch (e) { console.error('🚀 ~ insertProject ~ e:', e); handleErrorBackend(e); } } The variable dbos always looks correct, with the expected values and a matching ID. But selecting that same id in the variable test sometimes returns an empty array (even though dbos contained the correct object) 0|solid | Inserted project with ID: 78763 1 0|solid | 🚀 ~ insertProject ~ test: 78763 0 0|solid | Inserted project with ID: 78761 1 0|solid | 🚀 ~ insertProject ~ test: 78761 1 0|solid | Inserted project with ID: 78764 1 0|solid | 🚀 ~ insertProject ~ test: 78764 0
1 Reply
Lazer_Pope (Vossi / Hendrik)
The same happens for deletes. After deelting a row, it's still present in postgres.

Did you find this page helpful?