Skip to content

Error: Failed to convert rust String into napi string #13864

@sunneydev

Description

@sunneydev

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

  1. Reduce the amount of data queried at once by implementing pagination or using smaller batch sizes.
  2. Use cursors for more efficient pagination.
  3. Select only necessary fields to reduce the amount of data returned.
  4. 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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions