Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huge Int value in upsert causes: "PANIC: called Option::unwrap() on a None value in query-engine/core/src/query_document/parser.rs:250:87" #10049

Closed
elie222 opened this issue Nov 2, 2021 · 27 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: upsert nested upsert
Milestone

Comments

@elie222
Copy link

elie222 commented Nov 2, 2021

UPDATE: I can reproduce this error consistently.
It happens after sending quite high volume to Prisma. Nested upserts. It only starts to show after a few minutes.
Happening both locally and on our deployed servers.

Hi Prisma Team! My Prisma Client just crashed. This is the report:

Versions

Name Version
Node v14.15.3
OS darwin
Prisma Client 3.0.2
Query Engine 0.1.0
Database postgresql

What happened:
I was sending a high volume of upserts to Prisma. I can send the schema in private if needed.

Logs

 prisma:client:fetcher how you used Prisma Client in the issue. 
  prisma:client:fetcher 
  prisma:client:fetcher     at LibraryEngine.logger (project/db/node_modules/@prisma/client/runtime/index.js:25007:32)
  prisma:client:fetcher     at project/db/node_modules/@prisma/client/runtime/index.js:24977:36  
  prisma:client:libraryEngine sending request, this.libraryStarted: true  

Client Snippet

// PLEASE FILL YOUR CODE SNIPPET HERE

Schema

I can send the schema in private if needed.

// PLEASE ADD YOUR SCHEMA HERE IF POSSIBLE

Prisma Engine Query

{"X":{}}
@janpio
Copy link
Member

janpio commented Nov 2, 2021

Can you reproduce this consistently? Even more interesting, can you build a reproduction of it in an isolated project? I know we get these reports sometimes, but we could never reproduce them (reliably) ourselves and so are having a really hard time pinpointing what is going on.

@yassinebridi
Copy link

@janpio That is the issue, it's really hard to reproduce it, it happens sometimes, randomly, even if you have a workaround for one query, another query randomly does this.
#9795

@elie222
Copy link
Author

elie222 commented Nov 2, 2021

I can reproduce it. If I send a lot of queries it will happen after a few minutes. Happy to give repo access to the Prisma team if it helps you debug it properly.

@elie222
Copy link
Author

elie222 commented Nov 2, 2021

Any chance this will work better if I use queryRaw or it won't make any difference?
Other option is that I move this piece to another Postgres library.

@elie222
Copy link
Author

elie222 commented Nov 2, 2021

Latest update:

  • I'm setting a wait of 500ms between my upserts. I'm hopeful this has solved the issue. Possible I will find out it hasn't in an hour or two. 200ms gaps wasn't enough.
  • Happy to share repo access in private if it helps fix this bug. Or even walk through with a team member.

@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. labels Nov 3, 2021
@janpio
Copy link
Member

janpio commented Nov 3, 2021

  • Happy to share repo access in private if it helps fix this bug.

That would be nice. Can you please invite @janpio and @pantharshit00? Thanks.

Any chance this will work better if I use queryRaw or it won't make any difference?

That might be interesting to test actually. "Just" send the same queries the current Prisma Client call creates via queryRaw and see if it also triggers this problem. Actually might help us pinpoint the problem here.

I am really happy you found a workaround, even though it adds half a second delay between each upsert - I hope that is acceptable to you for now. We will look into this of course, especially as there are also other, related issues. Hope we can figure this out soon.

@elie222
Copy link
Author

elie222 commented Nov 4, 2021

So the workaround isn't perfect. Even with 500ms break it still happens but a lot less than before.

Was actually trying to reproduce the problem today locally but couldn't get it to crash locally (probably would have eventually if I waited long enough). I'll work on a demo repo and see if I can stress Prisma enough to resurface the bug on a consistent basis.

@janpio
Copy link
Member

janpio commented Nov 4, 2021

"Kinda consistent" is also fine, we just need something we can get to run in under half an hour with instructions on how to hammer it to probably cause the problem sooner or later.

@elie222
Copy link
Author

elie222 commented Nov 11, 2021

In response to:
#9795 (comment)

What is your Prisma version (prisma -v)?

prisma                  : 3.4.2
@prisma/client          : 3.4.2
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 57771c0558568c7d08bd34c7248af5244ae16bd9 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 57771c0558568c7d08bd34c7248af5244ae16bd9 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 57771c0558568c7d08bd34c7248af5244ae16bd9 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 57771c0558568c7d08bd34c7248af5244ae16bd9 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 57771c0558568c7d08bd34c7248af5244ae16bd9
Studio                  : 0.438.0

What OS? What Node version? What database and version?

MacOS but also on Linux in production.
v14.15.3
PostgreSQL 13

What is similar in the Prisma Client queries you are running?

Quite heavily nested but hard to pinpoint. A lot of upserts one after the other.

And most important: Does anyone have a (kinda) reliable reproduction of what is happening?

Yes, I can't reproduce in a fresh repo so will give access to our main one even though the set up takes more effort.

Will hopefully update with access in the next hour.

@elie222
Copy link
Author

elie222 commented Nov 11, 2021

Well I'm struggling to reproduce now. Which I guess is a good thing 🤷‍♂️
Although I can see it in my logs 62 times in the past few days :( I can't get it back to happening every few minutes consistently like it was before.

@elie222
Copy link
Author

elie222 commented Nov 12, 2021

Another update:
I can confirm it's still happening. But after around 500k upserts it happened only 4 times (although part of this is because we use a retry strategy and requeue in RabbitMQ). It's possible other changes on our end also improved things. One changed was updating Prisma from 3.0.2 to the latest 3.4.2 but there were others too.

If I can find a reproduction in the future I will share again. Always happy to add to the repo if you'd like to take a look around.

@pantharshit00
Copy link
Contributor

Yes, if you can share a reproduction, that would be great. Otherwise, it would be very hard to triage.

@pantharshit00 pantharshit00 added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Nov 12, 2021
@janpio janpio added the topic: upsert nested upsert label Nov 12, 2021
@elie222
Copy link
Author

elie222 commented Nov 23, 2021

This is still a major issue for us. If it helps get the ball rolling I can add to our GitHub repo and share the Sentry errors too.

I've tried to create simple and complex reproductions with no luck but we get a lot of errors for this issue consistently.

@elie222
Copy link
Author

elie222 commented Nov 25, 2021

The code in question where the PANIC error can happen:

export async function upsertEvent(myId: number, event: Prisma.EventCreateInput) {
  try {
    return await prisma.event.upsert({
      where: { myId },
      create: event,
      update: event,
    })

event is quite deep and depends on multiple collections. I can share in private if helpful.

@pantharshit00
Copy link
Contributor

@elie222 Share your reproduction to schemas@prisma.io privately. Then we can have a look and try to understand what is happening here.

@elie222
Copy link
Author

elie222 commented Nov 30, 2021

@elie222 Share your reproduction to schemas@prisma.io privately. Then we can have a look and try to understand what is happening here.

Will do.

Another update:
This bug only happens with nested upserts. We removed the nesting from our upserts and it hasn't happened at all now.

@enzojavier-desimone
Copy link

Same issue here when taking data from an API and doing a createMany, I was casting some number string to integer and a value was greater than the supported by the Int schema. Hard to debug because the error do not give any information.

@elie222
Copy link
Author

elie222 commented Feb 19, 2022

Same issue here when taking data from an API and doing a createMany, I was casting some number string to integer and a value was greater than the supported by the Int schema. Hard to debug because the error do not give any information.

Interesting. There's a chance that that was the issue for us too. We never found the actual cause of it just that unnesting fixed it.

@janpio
Copy link
Member

janpio commented Feb 19, 2022

Can you turn that into a reproduction @enzojavier-desimone?

@gleuch
Copy link

gleuch commented Mar 19, 2022

Same issue here when taking data from an API and doing a createMany, I was casting some number string to integer and a value was greater than the supported by the Int schema. Hard to debug because the error do not give any information.

Ditto. It took some debugging to narrow down to the specific input being passed into an upsert() call that causes this error. I'm able to trigger Option::unwrap() PANIC if an integer greater than Postgres's upper bound for Int is used in either create or update inputs options.

@janpio
Copy link
Member

janpio commented Mar 21, 2022

Same question to you, can you provide a minimal reproduction of this @gleuch? That would be amazing.
Then the others in this issue can also chime in if this could apply to their data as well.

@gleuch
Copy link

gleuch commented Mar 22, 2022

@janpio Example: https://github.com/gleuch/prisma-panic-example

@pantharshit00
Copy link
Contributor

Thanks for the reproduction @gleuch. I can confirm this issue now. We need to properly handle these panics.

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. process/candidate and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Mar 22, 2022
@janpio
Copy link
Member

janpio commented Mar 22, 2022

Everyone else who posted in this issue (@elie222 @yassinebridi @enzojavier-desimone), can you take a look at https://github.com/gleuch/prisma-panic-example/blob/main/index.js and confirm this could also be causing your issue?

@janpio janpio added the tech/engines Issue for tech Engines. label Mar 22, 2022
@enzojavier-desimone
Copy link

yes, exactly same issue in my case

@janpio janpio changed the title PANIC: called Option::unwrap() on a None value in query-engine/core/src/query_document/parser.rs:250:87 Huge Int value in upsert causes: "PANIC: called Option::unwrap() on a None value in query-engine/core/src/query_document/parser.rs:250:87" Mar 22, 2022
@elie222
Copy link
Author

elie222 commented Mar 22, 2022 via email

@dpetrick
Copy link
Contributor

dpetrick commented Jun 1, 2022

3.15 will ship a change that returns a structured error for over or underflowing integers instead of a panic.

@dpetrick dpetrick closed this as completed Jun 1, 2022
@janpio janpio added this to the 3.15.0 milestone Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: upsert nested upsert
Projects
None yet
Development

No branches or pull requests

7 participants