question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: connect EADDRNOTAVAIL 127.0.0.1 when Azure function app using Prisma, VNet integration enabled

See original GitHub issue

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

  1. Use Azure App Service Plan: Elastic Premium EP1 to use VNet integration
  2. Configure VNet Integration to function app (database is in 10.0.0.x, function subnet is 10.0.100.x)
  3. Deploy Azure function app using Prisma client
  4. Run export function which queries the MySQL database server
  5. 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 and sslmode from MySQL connection string

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
DavidChristiansencommented, Jun 22, 2021

Yes, Same issue - Azure Function (Windows) with VNET Integration. Happy to create a reproduction to aid testing.

1reaction
BeGjcommented, Sep 13, 2021

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error on npm start on Azure - EADDRNOTAVAIL
If you execute this start command in kudu, it is inappropriate. If an error occurs when running locally, such as connect EADDRNOTAVAIL 127.0.0.1...
Read more >
Invocation logs not showing when vnet integration is enabled
Hi,. I am looking for a solution when I have vnet integration on in my Azure function the invocation logs does not show...
Read more >
Deployment to Azure Function Apps with VNet integration not ...
We have Azure Function Apps with VNet integration configured in order ... In Kudu eventlog there are errors "Failed to open siteversion.txt.
Read more >
Use private endpoints to integrate Azure Functions with a ...
This tutorial shows you how to connect a function to an Azure virtual network and lock it down by using private endpoints.
Read more >
VNET integration with multiple Azure Functions hosted on two ...
6 Azure Functions hosted on a single App Service Plan - each function is integrated with the VNET / Subnet. Using Terraform I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found