prisma: Error: Failed to convert rust `String` into napi `string`
Latest reproduction
Still failing in version 6.0.1 I updated the test repo https://github.com/Quesstor/prisma-error
Bug Description
When querying large amounts of data (approximately 500MB or more), the following error occurs:
Error: Failed to convert rust `String` into napi `string`
at RequestHandler.request (/app/node_modules/@prisma/client/runtime/index.js:49022:15)
at async /app/build/services/data.service.js:8:20
at async PrismaClient._request (/app/node_modules/@prisma/client/runtime/index.js:49919:18)
at async getData (/app/build/services/data.service.js:16:25)
at async basicStatisticsController (/app/build/controllers/statistics/index.js:16:48)
This issue appears to be related to a memory limitation or possible memory leak in the Prisma client when handling large datasets.
How to Reproduce
The error occurs when querying data that is large in size, typically around 500MB or more. It has been observed that the error can be triggered with as few as 1,066 rows if the rows contain very large string properties (>500KB).
Example queries that can trigger this issue:
await prisma.table.findMany({
where: {
dateTime: {
gte: date.start,
lte: date.end,
},
},
});
// Or using raw SQL:
await prisma.$queryRaw`
SELECT * FROM "Table"
WHERE "dateTime" BETWEEN ${date.start} AND ${date.end}
`;
Expected Behavior
The query should complete successfully, regardless of the size of the result set.
Environment & Setup
- OS: Windows/Linux
- Database: PostgreSQL (hosted on AWS Aurora)
- Node.js version: 16.3+
- Prisma versions affected: 3.14, 3.15.2, 4.x, 5.x (including latest 5.5.2)
Workarounds
- Reduce the amount of data queried at once by implementing pagination or using smaller batch sizes.
- Use cursors for more efficient pagination.
- Select only necessary fields to reduce the amount of data returned.
- For large deletions with many relations, consider breaking down the operation into smaller steps.
Additional Notes
- The issue persists across different Node.js versions (including v20) and Prisma versions (up to 5.x).
- The problem seems to occur in the Rust engine used by Prisma, specifically in the napi package.
- Some users have reported success by splitting large queries into smaller chunks or by using alternative database drivers (e.g., mysql2 for MySQL databases).
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 62
- Comments: 81 (10 by maintainers)
@janpio @Jolg42 I’m just curios, why there is a critical bug open for 1,5 years?
typescript prisma shipped before this fix lmao
Good news everyone! It works with the new queryCompiler option: https://github.com/prisma/prisma/releases/tag/6.7.0
I also updated the test repo https://github.com/Quesstor/prisma-error and i get no errors anymore.
I think we can close this issue
Still failing in version 6.0.1 I updated the test repo https://github.com/Quesstor/prisma-error
What worked for me was being a better software engineer 😅
Instead of one giant
findManycalls, I made some changes to do small, but frequent calls instead with the same desired effect.Alright, i coded a reproduction example. You can find it at https://github.com/Quesstor/prisma-error
I had to make a few test to boil the problem down. The JSON contains a very long string property (>500kb) and you have to select a certain amount of rows (in my case it worked with 1066 rows and breaks with the 1067th one).
You can run the example by cloning the repo and simply run
docker compose up. The docker compose includes the postgres DB and the example app.We encountered this when querying a single record with several layers of deeply nested one-to-many relationships.
We were able to prevent this by first querying the top level object and first layer of one-to-many and then batching the second layer in another request.
I would not expect a single large response (~500KB+) resulting from large numbers of related objects to cause an error.
I’m experiencing this issue when querying a large amount of records with lots of data, dialing back the batch size is a workaround for me but not viable long-term. watching for a solution
Bump, experiencing this issue on a table with ~200k rows.
We are going to try and refactor the query into chunks to see if that fixes the issue.
Specific Prisma error from our lambda logs:
There’s a hard-coded string size limit in the V8 engine (JS engine that Node.js relies on). My thoughts are it might be related to that. It’s somewhere between 256 MB - 1 GB. I don’t know exactly.
This stack overflow issue might be useful
Updated it in the repo, keeps happening in version 5.5.2 Query is simply
await DB.document.findMany({ take: 1067 })I can also add that I’m experiencing very high memory usages when this error occurs.
Thank you for sharing solution. I use
mysql2insteadprismato handle big data. With your solution i think use cursor to increase performance https://www.prisma.io/docs/orm/prisma-client/queries/pagination#cursor-based-paginationI tried multiple things since being a bit lost:
v11instead of thev10): DOES NOT WORKv4.xtov5.x: DOES NOT WORKSo the latest solution I had was to split the call to make sure it passes:
In case it’s something the Prisma team has no control on, I would suggest having a more detailed log so people understand they reached kind of resource limits (or library limit).
@sunneydev don’t embarrass yourself
@slavaGanzin I think it’s because the error comes from a bad practice anyway. I don’t think you should be inserting a lot of rows at once.
We’re experiencing this as well with a complex query (with many includes) on a table with ~22K records (not that big) using latest
prisma@5.7.1on a Postgres 16.0 database.It’s a cron-like job that started to fail suddenly so we might have reach some kind of hard cap somewhere.
@tncn1122 @kulsbamby @lucas-coelho @alessandrofc @MrVhek @tadeumx1 Please add more information to your comments to make them more useful. In short, please don’t bump the issue if you have no information to share, you can use the 👍🏼 on the issue at the top to signal the same.
I’m definitely interested to know if this is happening with recent 5.X version of Prisma, like
5.5.2.Example:
npx prisma version.Thank you 💚
Hmm, the same problem here
I have also ran into this issue. In my case I noticed that a combination of two factors will trigger the issue:
agreed @thugzook haha
After selecting only the useful columns it worked here also. 😃
Running on a 32GB machine w/ 10GB page size on Node.js.
Same error for me. Was fine with ~170k entries, but I’m running into issues past that.
From your description I would assume it is mostly caused by the switch in versions between the branches. My guess would be that there is a rogue Prisma Client somewhere maybe in your
node_modulesor so.It is important that you do not delete the
node_modulesfolder of the original project that has this problem.Can you maybe check out the same project in another folder somewhere else, run
yarn installand then compare the new checkout with the old one, including all the files innode_modules? Maybe we can discover the difference this way.@janpio I’m tying to reproduce the error in simple project, but It does not work… but I can still reproduce it in my actual project easily. so I’ll keep trying to make the simple reproduce project.
current my founded reproducing work in my actual project is below.
I hope this gives you some insight.
Im using prisma 4.1.1 and postgreSQL 12.12 i have a lot of entries in one of my tables and i get this error when i try to findMany on it
Yes, If my device does not have a lot of RAM I get the error. I’m sure it’s some kind of memory leak, there’s no way the query could use 8 gigabytes of RAM.
No, the issue only occurs if it’s a lot of data in a single query.