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

Crash app error: touch(): PrismaClientKnownRequestError: #125

Open
Damiandeveloper26 opened this issue Apr 11, 2024 · 5 comments
Open

Crash app error: touch(): PrismaClientKnownRequestError: #125

Damiandeveloper26 opened this issue Apr 11, 2024 · 5 comments

Comments

@Damiandeveloper26
Copy link

Damiandeveloper26 commented Apr 11, 2024

Hello i got the problem with crashed app. After some times my app is crashing and it's random time ,no idea why. I'm using nest js with prisma session store.

There is error:
touch(): PrismaClientKnownRequestError:
Invalid this.prisma[this.sessionModelName].findUnique() invocation in
/Users/crasher/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:610:81

607 expiresAt = (0, utils_1.createExpiration)(ttl, {
608 rounding: this.options.roundTTL,
609 });
→ 610 return [4 /yield/, this.prisma[this.sessionModelName].findUnique(
Server has closed the connection.
Error: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:387:5)
at ServerResponse.setHeader (node:_http_outgoing:644:11)`

@kleydon
Copy link
Owner

kleydon commented Apr 13, 2024

Hi @Damiandeveloper26,
Thanks for posting.
Not sure what's going on.
Any nest js users have insight, here?

@bp26
Copy link

bp26 commented Apr 27, 2024

I am not using NestJs, only Express, but I have this error.

TypeError: Cannot read properties of undefined (reading 'findUnique') at PrismaSessionStore.<anonymous> (/opt/render/project/src/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:521:34) at step (/opt/render/project/src/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:63:23) at Object.next (/opt/render/project/src/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:44:53) at fulfilled (/opt/render/project/src/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:35:58) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

@nbercurrantsourcream
Copy link

nbercurrantsourcream commented May 17, 2024

touch(): PrismaClientKnownRequestError: 
Invalid `this.prisma[this.sessionModelName].update()` invocation in
*****/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:617:81

  614 existingSession = _b.sent();
  615 if (!(existingSession !== null)) return [3 /*break*/, 5];
  616 existingSessionData = __assign(__assign({}, this.serializer.parse((_a = existingSession.data) !== null && _a !== void 0 ? _a : '{}')), { cookie: session.cookie });
→ 617 return [4 /*yield*/, this.prisma[this.sessionModelName].update(
An operation failed because it depends on one or more records that were required but not found. Record to update not found.

So it looks like for some reason a session might not be in the db - and this throws in the extension -> which leads to the server trying to send error response and getting double headers somewhere down the line -> whih gets surfaced rather then this issue.

It would be best if the lib could
a) handle the potential "not found session" for touch operation -> instead of throwing and killing server
b) provide a way to handle those exceptions in app server code

Looks like touch and prune are missing .catch(()=>null) but it is present elsewhere

@kleydon
Copy link
Owner

kleydon commented May 18, 2024

@Damiandeveloper26 Thanks for pointing this out.
Not sure when I'd have a chance to get to this, but if you feel like posting a PR, I can try to get it reviewed within a week.

@nbercurrantsourcream
Copy link

nbercurrantsourcream commented May 20, 2024

To be fair, in my case it looks like it's a race condition - I'm facing this in e2e tests only so far.

From what I was able to gather it looks like;

  • some part of the flow is trying to modify a session that has been hard removed
    -> this leads to prisma-store executing callback with the error
    => and looks like express session then just re-throws/does not handle the exception in a way that would let the server recover

Looking at some other session stores - looks like some don't even implement touch so maybe it can not throw? I'll try it in a fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants