prisma: Error: connect EADDRNOTAVAIL 127.0.0.1 when Azure function app using Prisma, VNet integration enabled
Bug description
Azure function app uses Prisma 2 to select data from MySQL database server on virtual private network. When querying the data, function app crashes with the following error message with changing port number:
2021-02-25T09:21:33.515 [Error] Executed 'Functions.offline-data-exporter' (Failed, Id=b4889147-xxxx-xxxx-xxx-
xxxxxxxxxxx, Duration=1554ms)
Result: FailureException: Error:Invalid `prisma.disconnector.findMany()` invocation
in D:\home\site\wwwroot\dist\shared\offline-data-exporter.js:15:84
connect EADDRNOTAVAIL 127.0.0.1 - Local (0.0.0.0:50306)Stack: Error:Invalid `prisma.disconnector.findMany()`
invocation in D:\home\site\wwwroot\dist\shared\offline-data-exporter.js:15:84
connect EADDRNOTAVAIL 127.0.0.1 - Local (0.0.0.0:50306)at PrismaClientFetcher.request
(D:\home\site\wwwroot\node_modules\@prisma\client\runtime\index.js:78585:15)at processTicksAndRejections (internal/process/task_queues.js:97:5)
How to reproduce
- Use Azure App Service Plan: Elastic Premium EP1 to use VNet integration
- Configure VNet Integration to function app (database is in 10.0.0.x, function subnet is 10.0.100.x)
- Deploy Azure function app using Prisma client
- Run export function which queries the MySQL database server
- See error above
Expected behavior
Database disconnector table query results should be returned normally.
Database querying has been working properly with the same setup until the beginning of February. Upgrading or downgrading Prisma, or even deploying the last known working version of function app does not solve the problem. Creating a new app with similar settings does not work either.
The same exporter code works fine on two other Azure environments using Azure MySQL for database without VNet integration enabled in function app.
Using mysql2 to connect and query disconnector data from VNet database server works ok.
Prisma information
prisma.schema:
datasource network {
provider = "mysql"
url = "mysql://user:pass@10.0.0.x/database?connection_limit=1&sslmode=disable" // sample, read from env, see below
}
generator client {
provider = "prisma-client-js"
}
model Disconnector {
code String @id
name String
protectiveEarthing Float? @map(name: "protective_earthing")
systemEarthing Float? @map(name: "system_earthing")
totalEarthing Float? @map(name: "combined_earthing")
measurementDate DateTime? @map(name: "measure_date")
data Json
@@map(name: "disconnector")
}
data-exporter.ts:
const prisma = new PrismaClientFactory().create(network);
try {
await prisma.$connect();
const disconnectors = this.asDisconnectorDto(
await prisma.disconnector.findMany(),
await prisma.$queryRaw<
LocationData[]
>`SELECT code, ST_AsText(loc) AS spatialData FROM disconnector;`,
projection
);
await prisma.$disconnect();
....
} finally {
await prisma.$disconnect();
}
prisma-client-factory.ts - code from last known working commit using Prisma v2.10.2. Reads connection string from env and replaces the database portion:
export class PrismaClientFactory {
create(network: string): PrismaClient {
const database = `abcdef_${network}`;
const prisma = new PrismaClient({
// log: ["query", "info"],
datasources: {
network: {
url: process.env.MYSQL_CONNECTION_STRING?.replace(
"${database}",
database
),
provider: "mysql",
},
},
});
return prisma;
}
}
Environment & setup
- OS: Azure function app on Windows machine with VNet integration enabled
- Database: MySQL 5.7 on private virtual network
- Node.js version: v12.18.0, also tested with setting Node 14 LTS in Azure function app settings
- Prisma version: 2.10.2 and 2.17.0 both tested
tcpping
can reach database server and port 3306 from function app console.
See MySQL connection string example format in Prisma schema code.
Additional checks done
The following have been checked:
- database connection string is ok and database user can connect to database and has sufficient rights
- deployed function app has been stopped and restarted
- database query works normally using mysql2 library
- VNet integration subnet 10.0.100.x is connected and working correctly on other function apps not using Prisma
The following have been tried and none of these have worked:
- upgrading Prisma version to 2.17.0 and re-deploying the function app
- downgrading back to 2.10.2 and re-deploying the function app
- building release from the last known working commit and re-deploying the function app
- deploying code to new function app with similar configuration built from ground up
- removing
connection_limit
andsslmode
from MySQL connection string
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (6 by maintainers)
Yes, Same issue - Azure Function (Windows) with VNET Integration. Happy to create a reproduction to aid testing.
@janpio Sorry. This was the most related issue I were able to find… Trying again in a newdiscussion https://github.com/prisma/prisma/discussions/9228
That sounds pretty unrelated @BeGj. Please open a new issue or discussion about this for you unexpected behavior so we can look into it.
Hmm, this seems unrelated to binary process then. Try increasing the connection timeout once. It might be failing before attaining a connection.
Add this to your connection string:
?connect_timeout=30&pool_timeout=30&socket_timeout=30