Failed to run future: no available capacity / QueueFull
See original GitHub issueBug description
am currently trying to import a large dataset into my database using prisma. I get my data from a csv file which has more than 15,000 rows. unfortunately I run into the following error:
PrismaClientKnownRequestError2 [PrismaClientKnownRequestError]:
Invalid `prisma.medicament.create()` invocation:
Failed to run future: no available capacity
at cb (/home/user/Documents/VSCode/Altea/DPI/api/node_modules/@prisma/client/runtime/index.js:34780:17)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Parser.<anonymous> (/home/user/Documents/VSCode/Altea/DPI/api/dist/app.service.js:97:32) {
code: 'QueueFull',
clientVersion: '2.21.2',
meta: undefined
How to reproduce
Steps to reproduce the behavior:
- create a new nestjs project
- install prisma and csv
- create prisma schema and connect a database
- use filesystem and csv to read a big csv file and save each line in your database using prisma client
- See error
Expected behavior
All the row to be saved in the database, instead only some are
Prisma information
Prisma schema
// This is your Prisma schema folder,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["selectRelationCount", "orderByRelation", "orderByAggregateGroup"]
}
generator nestgraphql {
provider = "node node_modules/prisma-nestjs-graphql"
output = "../src/graphql"
}
/// Defini le sex du patient
enum SEX {
MALE
FEMALE
}
/// Defini l'etat actuel du sejour
enum FOLDERSTATUS {
WAITING
READY
OPEN
PENDING
CLOSED
}
/// Defini le type de dossier patient
enum FOLDERTYPE {
EXTERNE
OBSERVATION
URGENCE
HOSPITALISATION
}
/// Defini le type de l'acte effectue
enum ACTTYPE {
RADIO
LABORATOIRE
MEDICAL
INFIRMIER
AUTRE
}
enum ADMINISTRATIONROUTE {
ORALE
INJECTION
SUBLINGUALE
RECTALE
VAGINALE
OCULAIRE
AURICULAIRE
NASALE
INHALATION
NEBULISATION
CUTANEE
TRANSDERMIQUE
}
/// Represente un utitlisateur de l'application
model User {
id String @id @default(uuid())
email String @unique
/// @HideField()
password String
role Role? @relation(fields: [role_id], references: [id])
/// @HideField()
role_id String?
name String
/// @onDelete(SET NULL)
folders Folder[]
}
/// Represente les roles que les utilisateurs peuvent avoir
model Role {
id String @id @default(uuid())
/// @onDelete(SET NULL)
users User[]
name String @unique
}
/// Represente les dossier de patients
model Patient {
id String @id @default(uuid())
phone String
email String @unique
name String
birthdate String
sex SEX
picture String?
address String?
folders Folder[]
/// @onDelete(CASCADE)
antecedents AntecedentPatient[]
/// @onDelete(CASCADE)
allergies AllergyPatient[]
}
/// Represente les antecedents des differents patients
model Antecedent {
id String @id @default(uuid())
//type ANTECEDENTTYPE
description String @unique
/// @onDelete(CASCADE )
patients AntecedentPatient[]
}
model AntecedentPatient {
id String @id @default(uuid())
antecedent Antecedent? @relation(fields: [antecedent_id], references: [id])
/// @HideField()
antecedent_id String?
patient Patient? @relation(fields: [patient_id], references: [id])
/// @HideField()
patient_id String?
commentary String?
active Boolean @default(true)
created_at DateTime @default(now())
}
model Allergy {
id String @id @default(uuid())
substance String @unique
/// @onDelete(CASCADE)
patients AllergyPatient[]
}
model AllergyPatient {
id String @id @default(uuid())
allergy Allergy? @relation(fields: [allergy_id], references: [id])
/// @HideField()
allergy_id String?
patient Patient? @relation(fields: [patient_id], references: [id])
/// @HideField()
patient_id String?
commentary String?
active Boolean @default(true)
created_at DateTime @default(now())
}
/// Represente les sejours des patients
model Folder {
id String @id @default(uuid())
controls Folder[] @relation("FolderToFolder")
patient Patient? @relation(fields: [patient_id], references: [id])
/// @HideField()
patient_id String?
doctor User? @relation(fields: [doctor_id], references: [id])
/// @HideField()
doctor_id String?
constants Json[]
observations String?
diagnostics String?
type FOLDERTYPE @default(EXTERNE)
prescriptions Prescription[]
date_start DateTime @default(now())
date_end DateTime?
consultation Folder? @relation("FolderToFolder", fields: [consultation_id], references: [id])
/// @HideField()
consultation_id String?
status FOLDERSTATUS @default(WAITING)
/// @onDelete(CASCADE)
protocols FolderProtocol[]
acts ActFolder[]
}
model FolderProtocol {
id String @id @default(uuid())
folder Folder? @relation(fields: [folder_id], references: [id])
/// @HideField()
folder_id String?
protocol Protocol? @relation(fields: [protocol_id], references: [id])
/// @HideField()
protocol_id String?
commentary String?
created_at DateTime @default(now())
}
/// Represente les protocols medicaux
model Protocol {
id String @id @default(uuid())
name String
description String?
prescriptions Prescription[]
/// @onDelete(CASCADE)
folders FolderProtocol[]
/// @onDelete(CASCADE)
acts ActProtocol[]
}
/// Represente les prescriptions effectuees
model Prescription {
id String @id @default(uuid())
type String
quantity Int
posology String
duration Int @default(0)
protocols Protocol[]
/// @HideField()
folder_id String?
folder Folder? @relation(fields: [folder_id], references: [id])
medicament Medicament? @relation(fields: [medicament_id], references: [id])
/// @HideField()
medicament_id String?
}
/// Represente les actes effectues
model Act {
id String @id @default(uuid())
type ACTTYPE
category String?
wording String
/// @onDelete(CASCADE)
protocols ActProtocol[]
/// @onDelete(CASCADE)
folders ActFolder[]
}
model ActProtocol {
id String @id @default(uuid())
act Act? @relation(fields: [act_id], references: [id])
protocol Protocol? @relation(fields: [protocol_id], references: [id])
/// @HideField()
act_id String?
/// @HideField()
protocol_id String?
description String?
created_at DateTime @default(now())
}
model ActFolder {
id String @id @default(uuid())
act Act? @relation(fields: [act_id], references: [id])
folder Folder? @relation(fields: [folder_id], references: [id])
/// @HideField()
act_id String?
/// @HideField()
folder_id String?
results Json?
commentary String?
intern Boolean @default(true)
status String @default("PENDING")
created_at DateTime @default(now())
}
// Data from medicine database
model Medicament {
id String @id @default(uuid())
code_cis Int @unique
denomination String
forme_pharmaceutique String
voie_administration String?
statut_administratif String?
type_procedure_autorisation String?
etat_commercialisation String?
date_amm DateTime?
statut_bdm String?
numero_autorisation String?
titulaire String?
surveillance_renforcee Boolean?
compositions CompositionMedicament[]
prescriptions Prescription[]
}
model CompositionMedicament {
id String @id @default(uuid())
code_cis Int?
designation_element_pharmaceutique String?
code_substance Int?
denomination String?
dosage String?
reference_dosage String?
nature_composant String?
numero_lieur Int?
medicament Medicament? @relation(fields: [code_cis], references: [code_cis])
}
Prisma client
import { Injectable, OnModuleDestroy, OnModuleInit } from "@nestjs/common";
import { onDeleteArgs, PrismaDelete } from "@paljs/plugins";
import { PrismaClient } from "@prisma/client";
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
async onDelete(args: onDeleteArgs) {
const prismaDelete = new PrismaDelete(this);
await prismaDelete.onDelete(args);
}
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy() {
await this.$disconnect();
}
}
Code used to populate database
async migrateMedicament() {
const stream = createReadStream(
"/home/user/Documents/VSCode/CIS_MEDS_UTF-8/CIS_bdpm/CIS_bdpm_1.txt",
{
encoding: "utf8",
}
);
stream
.on("error", (err) => {
console.log("error stream: ", err);
})
.pipe(
csvParse({
delimiter: "\t",
//ignore_last_delimiters: false,
//record_delimiter: "\t\r\n",
cast: (value, context) => {
if (context.index === 0) {
return parseInt(value);
} else if (context.index === 7) {
return dateParse(value, "dd/MM/yyyy", new Date());
} else if (context.index === 11) {
return value === "oui" ? true : false;
} else return value;
},
columns: [
"code_cis",
"denomination",
"forme_pharmaceutique",
"voie_administration",
"statut_administratif",
"type_procedure_autorisation",
"etat_commercialisation",
"date_amm",
"statut_bdm",
"numero_autorisation",
"titulaire",
"surveillance_renforcee",
],
})
)
.on("data", async (row) => {
try {
const result = await this.prismaService.medicament.create({
data: row,
});
} catch (error) {
console.error(`while inserting ${row.code_cis} in db: `, error);
}
});
}
Environment & setup
- OS: Ubuntu 20.04
- Database: PostgreSQL 13
- Node.js version: v14. 16.1
- Prisma version: 2.21.2
- File used for database seeding CIS_bdpm.txt
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Agent unable to register with SAAS/On-prem control...
We are trying to deploy Java Agent in our WildFly 10.1.0 Using Java Agent Version [Server Agent #21.3.0.32281 v21.3.0] we are having SAAS...
Read more >Disable log flood XRStats::SetStatFloat Failed. Stats queue full ...
Hello @AVOlight, There is no way to disable stats completely right now. I will bring this up with my team to see if...
Read more >How do I resolve the error "Re-execute limit reached..."? - IBM
In general, this error occurs in exceptional situations within the Event Manager , such as a "queue full condition" of the monitor event...
Read more >Prisma 2.24.1 Release - GitClear
Prisma Client · In 2.24. · Performance regression with napi for high concurrency #7404 · Failed to run future: no available capacity /...
Read more >Prism pc.2022.6 - Alerts/Health checks - Nutanix Support Portal
Snapshots of the protection domain will not be available on the remote ... Impact, Background cluster maintenance tasks might get affected in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No need after https://github.com/napi-rs/napi-rs/pull/597
It does looks like increasing the buffer size helps here. I guess we can document this. This should be only used when someone is processing large dataset at once.