prisma / prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)
Apache License 2.0
1.47k stars 67 forks source link

prisma client error on aws lambda #774

Closed j0sh-park closed 4 years ago

j0sh-park commented 4 years ago

I deployed my application on aws lambda with serverless and this is my handler

const app = serverless(createServer())
export const handler: Handler = async (event: any, context) => {
    context.callbackWaitsForEmptyEventLoop = false
    return await app(event, context)
}

and my server

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

export interface Context {
    prisma: PrismaClient
    user: any | undefined
}

export function createContext({ ctx }: any): Context {
    return { prisma, user: ctx.state.user }
}

function applyApolloServer(app: Koa) {
    const graphqlPath = `/graphql`

    const apolloServer = new ApolloServer({
        schema: index,
        context: createContext,
        uploads: {
            maxFiles: 10,
            maxFileSize: 1024 * 1024 * 100,
        },
        formatError: (error) => {
            console.error(error)
            return error
        },
    })
    apolloServer.applyMiddleware({ app, path: graphqlPath })
    return apolloServer
}

When I try to make 50k request It occurs errors below only in aws lambda it's fine on docker or my mac the errors occur sometimes like 50 times of 50k and if a error occurs it comes with several errors together and become fine again it seems like the error occurs with new lambda container or cold start

Versions

+Versions

+Name+++++ +Version++++++++++++
+Node+++++ +v12.16.3+++++++++++ +
+OS+++++++ +rhel-openssl-1.0.x+
+Prisma+++ +2.2.0++++++++++++++

+Logs

TE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:52.713Z+prisma-client+Generated+request:
2020-07-11T15:52:52.713Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:52.743Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:52.743Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:52.743Z+prisma-client+Generated+request:
2020-07-11T15:52:52.743Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:53.132Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:53.132Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:53.132Z+prisma-client+Generated+request:
2020-07-11T15:52:53.132Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:53.175Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:53.175Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:53.176Z+prisma-client+Generated+request:
2020-07-11T15:52:53.176Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:53.226Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:53.226Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:53.226Z+prisma-client+Generated+request:
2020-07-11T15:52:53.226Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:53.619Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:53.619Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:53.619Z+prisma-client+Generated+request:
2020-07-11T15:52:53.619Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:54.009Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:54.009Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:54.009Z+prisma-client+Generated+request:
2020-07-11T15:52:54.009Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:54.025Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:54.025Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:54.026Z+prisma-client+Generated+request:
2020-07-11T15:52:54.026Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:54.069Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:54.069Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:54.069Z+prisma-client+Generated+request:
2020-07-11T15:52:54.069Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:54.612Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:54.612Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:54.612Z+prisma-client+Generated+request:
2020-07-11T15:52:54.612Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:56.138Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:56.138Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:56.138Z+prisma-client+Generated+request:
2020-07-11T15:52:56.138Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:56.297Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:56.297Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:56.297Z+prisma-client+Generated+request:
2020-07-11T15:52:56.297Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:56.504Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:56.504Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:56.504Z+prisma-client+Generated+request:
2020-07-11T15:52:56.504Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:56.517Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:56.517Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:56.517Z+prisma-client+Generated+request:
2020-07-11T15:52:56.517Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:56.598Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:56.598Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:56.598Z+prisma-client+Generated+request:
2020-07-11T15:52:56.598Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:57.124Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:57.124Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:57.125Z+prisma-client+Generated+request:
2020-07-11T15:52:57.125Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:52:57.474Z+prisma-client+Prisma+Client+call:
2020-07-11T15:52:57.474Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:52:57.474Z+prisma-client+Generated+request:
2020-07-11T15:52:57.474Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:53:04.159Z+prisma-client+Prisma+Client+call:
2020-07-11T15:53:04.159Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:53:04.160Z+prisma-client+Generated+request:
2020-07-11T15:53:04.160Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}

2020-07-11T15:54:05.450Z+prisma-client+Prisma+Client+call:
2020-07-11T15:54:05.450Z+prisma-client+prisma.queryRaw(UPDATE+"ShareApplication"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk')
2020-07-11T15:54:05.450Z+prisma-client+Generated+request:
2020-07-11T15:54:05.450Z+prisma-client+mutation+{
++queryRaw(query:+"UPDATE+\"ShareApplication\"+SET+count+=+count+++1+WHERE+code+=+'68b9kvtk9jbk'")
}
j0sh-park commented 4 years ago

I solved this problem with prisma.disconnect() when every request finished