Repository: prisma/prisma-client-js

Issue #789: AWS Lambda: Unknown error in Prisma Client
Created: 2020-07-19T20:13:37Z
Hi there, I am building a serverless application using Prisma on AWS Lambda functions. I based my serverless.com project on the official Lambda example. However, I am experiencing an issue with my Prisma Client invocations. This seems to happen sporadically and without a traceable reason.
Prisma generated report
Hi Prisma Team! My Prisma Client just crashed. This is the report:
Versions



Name
Version




Node
v12.16.3


OS
rhel-openssl-1.0.x


Prisma
2.2.0



Logs
2020-07-19T20:01:11.490Z prisma-client {
  engineConfig: {
    cwd: '/var/task/node_modules/.prisma/client',
    debug: false,
    datamodelPath: '/var/task/node_modules/.prisma/client/schema.prisma',
    prismaPath: undefined,
    engineEndpoint: undefined,
    generator: {
      name: 'client',
      provider: 'prisma-client-js',
      output: '/Users/alexrv99/Projects/positive-zero/its-covid/its-covid-api/node_modules/@prisma/client',
      binaryTargets: [Array],
      experimentalFeatures: [Array],
      config: {}
    },
    showColors: false,
    logLevel: undefined,
    logQueries: undefined,
    flags: [],
    clientVersion: '2.2.0',
    enableExperimental: [ 'aggregations' ]
  }
}
2020-07-19T20:01:11.520Z prisma-client Prisma Client call:
2020-07-19T20:01:11.521Z prisma-client prisma.applicant.findOne({
  where: {
    applicantId: '37525'
  }
})
2020-07-19T20:01:11.521Z prisma-client Generated request:
2020-07-19T20:01:11.521Z prisma-client query {
  findOneApplicant(where: {
    applicantId: "37525"
  }) {
    id
    number
    createdAt
    updatedAt
    careerName
    applicantId
    cenevalId
    fatherLastName
    motherLastName
    name
    email
    password
    classroom
    applicationTime
    startTime
  }
}

2020-07-19T20:01:11.526Z plusX Execution permissions of /var/task/node_modules/.prisma/client/query-engine-rhel-openssl-1.0.x are fine
2020-07-19T20:01:11.764Z prisma-client Client Version 2.2.0
2020-07-19T20:01:11.764Z prisma-client Engine Version 45c4da4dd3ccd6a322796b228bdf937c7ce884e8
2020-07-19T20:01:20.602Z prisma-client Prisma Client call:
2020-07-19T20:01:20.602Z prisma-client prisma.applicant.findOne({
  where: {
    applicantId: '37525'
  }
})
2020-07-19T20:01:20.602Z prisma-client Generated request:
2020-07-19T20:01:20.602Z prisma-client query {
  findOneApplicant(where: {
    applicantId: "37525"
  }) {
    id
    number
    createdAt
    updatedAt
    careerName
    applicantId
    cenevalId
    fatherLastName
    motherLastName
    name
    email
    password
    classroom
    applicationTime
    startTime
  }
}

2020-07-19T20:01:25.698Z prisma-client Prisma Client call:
2020-07-19T20:01:25.698Z prisma-client prisma.applicant.findOne({
  where: {
    applicantId: ''
  }
})
2020-07-19T20:01:25.698Z prisma-client Generated request:
2020-07-19T20:01:25.698Z prisma-client query {
  findOneApplicant(where: {
    applicantId: ""
  }) {
    id
    number
    createdAt
    updatedAt
    careerName
    applicantId
    cenevalId
    fatherLastName
    motherLastName
    name
    email
    password
    classroom
    applicationTime
    startTime
  }
}

2020-07-19T20:01:32.005Z prisma-client Prisma Client call:
2020-07-19T20:01:32.005Z prisma-client prisma.applicant.findOne({
  where: {
    applicantId: '37525'
  }
})
2020-07-19T20:01:32.005Z prisma-client Generated request:
2020-07-19T20:01:32.005Z prisma-client query {
  findOneApplicant(where: {
    applicantId: "37525"
  }) {
    id
    number
    createdAt
    updatedAt
    careerName
    applicantId
    cenevalId
    fatherLastName
    motherLastName
    name
    email
    password
    classroom
    applicationTime
    startTime
  }
}

2020-07-19T20:01:40.212Z prisma-client Prisma Client call:
2020-07-19T20:01:40.212Z prisma-client prisma.applicant.findOne({
  where: {
    applicantId: '35635'
  }
})
2020-07-19T20:01:40.212Z prisma-client Generated request:
2020-07-19T20:01:40.212Z prisma-client query {
  findOneApplicant(where: {
    applicantId: "35635"
  }) {
    id
    number
    createdAt
    updatedAt
    careerName
    applicantId
    cenevalId
    fatherLastName
    motherLastName
    name
    email
    password
    classroom
    applicationTime
    startTime
  }
}

2020-07-19T20:03:41.871Z prisma-client Prisma Client call:
2020-07-19T20:03:41.871Z prisma-client prisma.applicant.findOne({
  where: {
    applicantId: '36658'
  }
})
2020-07-19T20:03:41.871Z prisma-client Generated request:
2020-07-19T20:03:41.871Z prisma-client query {
  findOneApplicant(where: {
    applicantId: "36658"
  }) {
    id
    number
    createdAt
    updatedAt
    careerName
    applicantId
    cenevalId
    fatherLastName
    motherLastName
    name
    email
    password
    classroom
    applicationTime
    startTime
  }
}

Duplicate issue #791: Prisma Query Engine has a panic - AWS Lambda + Aurora Serverless
Created: 2020-07-20T12:45:24Z
Hi Prisma Team,
I'm using Prisma together with Apollo Server Lambda and Aurora Serverless Postgres.
At first glance, everything seems to run smooth and work as expected. Prisma Client fires and resolves queries as requested.
BUT after about 1 min of inactivity (the Lambda is still warm and Aurora Serverless is alive) I receive the following error:
Error:
Invalid `prisma.user.findOne()` invocation in
/var/task/resolvers/Query.js:29:34

Unknown error in Prisma Client
This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.

Logging to stdout I find the following additional information.
engine {
  error: SocketError: other side closed
  at Socket.<anonymous> (/opt/nodejs/node_modules/prisma-client/runtime/index.js:1:81651)
  at Socket.emit (events.js:322:22)
  at endReadableNT (_stream_readable.js:1187:12)
  at processTicksAndRejections (internal/process/task_queues.js:84:21) {
   code: 'UND_ERR_SOCKET'
  }
}

Any ideas, what is wrong here? After receiving the error and firing the next request, everything works as expected again, until I pause another minute. Thank you all in advance. Prisma is great by the way, you're awesome!
Essential Code:
// Apollo Server and Lambda Handler 
import { ApolloServer, makeExecutableSchema } from 'apollo-server-lambda';
import { importSchema } from 'graphql-import';
import { PrismaClient } from 'prisma-client';
import { resolvers } from 'resolvers';

const typeDefs = importSchema('schema/schema.graphql');
const schema = makeExecutableSchema({ typeDefs, resolvers });
const prisma = new PrismaClient();
const context = () => ({ prisma });

const server = new ApolloServer({
  schema,
  context,
  playground: { endpoint: '/prod' },
  engine: { sendReportsImmediately: true },
  tracing: false,
  debug: true,
});

const apolloHandler = server.createHandler({
  cors: {
    origin: '*',
    credentials: true,
  },
});

exports.handler = (event, context, callback) => {
  context.callbackWaitsForEmptyEventLoop = false;
  return apolloHandler(event, context, callback);
};
// From my resolvers
export const getUser = async (_parent, { id }, { prisma }, _info) => {
  const where = { id };
  const user = await prisma.user.findOne({ where });
  return user;
};
Some more background:

Running Lambda@Edge
Aurora Serverless Postgres 10.7
Lambda and Aurora share common VPC with 2x isolated Subnets
Prisma lives in a Lambda Layer (incorporating it into the Lambda itself has no effect on the error)

Please see Prisma log report below:
My Prisma Client just crashed. This is the report:
Versions



Name
Version




Node
v12.16.3


OS
rhel-openssl-1.0.x


Prisma
2.2.2



Logs
2020-07-20T12:09:55.273Z prisma-client {
  engineConfig: {
    cwd: '/opt/nodejs/node_modules/prisma-client',
    debug: false,
    datamodelPath: '/opt/nodejs/node_modules/prisma-client/schema.prisma',
    prismaPath: undefined,
    engineEndpoint: undefined,
    generator: {
      name: 'client',
      provider: 'prisma-client-js',
      output: '/path_to_custom_prisma_client_folder/prisma-client',
      binaryTargets: [Array],
      experimentalFeatures: [Array],
      config: {},
      isCustomOutput: true
    },
    showColors: false,
    logLevel: 'error',
    logQueries: false,
    flags: [],
    clientVersion: '2.2.2',
    enableExperimental: [ 'aggregations' ]
  }
}
2020-07-20T12:09:55.527Z prisma-client Prisma Client call:
2020-07-20T12:09:55.547Z prisma-client prisma.user.findOne({
  where: {
    id: 'f713c7cd-d35d-4b46-820e-5e0ed147895f'
  }
})
2020-07-20T12:09:55.547Z prisma-client Generated request:
2020-07-20T12:09:55.547Z prisma-client query {
  findOneUser(where: {
    id: "f713c7cd-d35d-4b46-820e-5e0ed147895f"
  }) {
    id
    createdAt
    email
    password
  }
}

2020-07-20T12:09:55.686Z plusX Execution permissions of /opt/nodejs/node_modules/prisma-client/query-engine-rhel-openssl-1.0.x are fine
2020-07-20T12:09:57.568Z prisma-client Client Version 2.2.2
2020-07-20T12:09:57.586Z prisma-client Engine Version a9e8c3d97ef2a0cf59256e6b26097f2a80f0a6a4
2020-07-20T12:10:40.169Z prisma-client Prisma Client call:
2020-07-20T12:10:40.186Z prisma-client prisma.user.findOne({
  where: {
    id: 'f713c7cd-d35d-4b46-820e-5e0ed147895f'
  }
})
2020-07-20T12:10:40.186Z prisma-client Generated request:
2020-07-20T12:10:40.186Z prisma-client query {
  findOneUser(where: {
    id: "f713c7cd-d35d-4b46-820e-5e0ed147895f"
  }) {
    id
    createdAt
    email
    password
  }
}

2020-07-20T12:12:49.367Z prisma-client Prisma Client call:
2020-07-20T12:12:49.386Z prisma-client prisma.user.findOne({
  where: {
    id: 'f713c7cd-d35d-4b46-820e-5e0ed147895f'
  }
})
2020-07-20T12:12:49.386Z prisma-client Generated request:
2020-07-20T12:12:49.386Z prisma-client query {
  findOneUser(where: {
    id: "f713c7cd-d35d-4b46-820e-5e0ed147895f"
  }) {
    id
    createdAt
    email
    password
  }
}

Closing comment (2020-07-22T12:45:45Z): Closing as a duplicate of #789