Error getaddrinfo enotfound postgres

What are you doing? I am running a microservice with sequelize and postgres it seems to properly connect to the database when running node app but on migrations it throws this error Sequelize CLI [...

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


Closed

Rolilink opened this issue

May 29, 2019

· 11 comments

Comments

@Rolilink

What are you doing?

I am running a microservice with sequelize and postgres it seems to properly connect to the database when running node app but on migrations it throws this error

Sequelize CLI [Node: 8.16.0, CLI: 5.4.0, ORM: 5.7.4]

Loaded configuration file "lib/sequelize/config.js".


ERROR: getaddrinfo ENOTFOUND postgres postgres:5432

Environment

Dialect:

  • mysql
  • postgres
  • sqlite
  • mssql
  • any
    Dialect library version: Don’t Know
    Database version: Don’t Know
    Sequelize version: 5.4.0 CLI
    Node Version: 8.16.0
    OS: docker
    If TypeScript related: TypeScript version: XXX
    Tested with latest release:
  • No
  • Yes, specify that version:

@papb

Can you provide a MCVE? Perhaps a gitlab repo where you can use docker-compose to show the problem?

@okabamac

Please were you able to solve this? My connection is established but when I run migration it tells the address is not found

@dizthewize

Please were you able to solve this? My connection is established but when I run migration it tells the address is not found

Same here

@WinjayYu

Please were you able to solve this? My connection is established but when I run migration it tells the address is not found

Same here

Same…

Update: If your postgres service is not ready, the sequelize can not get postgres container IP. So you should add
a statement in backend service in docker-compose.yaml. like this:

BTW. Docker compose v3 no longer supports the condition form of depends_on. You can use a tool such as wait-for-it to waiting for a postgres to be ready is really.

@gambinish

Please were you able to solve this? My connection is established but when I run migration it tells the address is not found

Same issue here.

@sahilsharmafrank

in your config.json use hopefully it will solve the problem
"development": { ... "host": "host.docker.internal" .... }

@raulneitor

in your config.json use hopefully it will solve the problem
"development": { ... "host": "host.docker.internal" .... }

it works for meee

anivanchen

added a commit
to stuysu/old-junior.stuysu.org
that referenced
this issue

Nov 6, 2021

@anivanchen

@github-actions

This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the «stale» label. 🙂

@MadaShindeInai

in your config.json use hopefully it will solve the problem "development": { ... "host": "host.docker.internal" .... }

«development»: { … «host»: «localhost» …. }. — solved my problem

@masioware

@ephys

I’m closing because this doesn’t sound like a Sequelize issue but a general issue with node and docker’s domain name resolver (it looks like the URL in the original post uses postgres as the domain name). Using localhost or 0.0.0.0 instead usually works, along with the other solutions already provided in the thread

Содержание

  1. NodeJS Postgres error getaddrinfo ENOTFOUND
  2. 8 Answers 8
  3. Error: getaddrinfo ENOTFOUND when sending https request Node.js and API
  4. 3 Answers 3
  5. Linked
  6. Related
  7. Hot Network Questions
  8. Subscribe to RSS
  9. «Error: getaddrinfo ENOTFOUND» error when making an HTTPs request
  10. 4 Answers 4
  11. Error : getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443
  12. 17 Answers 17
  13. Update
  14. Update 2
  15. Update 3
  16. getaddrinfo ENOTFOUND api.telegram.org #99
  17. Comments

NodeJS Postgres error getaddrinfo ENOTFOUND

I use pg://user:pass@localhost:port/table for connecting to my AWS database. When I use localhost, the app works fine, but when I try to connect the AWS server it falls apart.

Even a simple connection code gives me this error. The database name is people and it’s running on port 8080 but in this error it’s showing 5432 even if I declare the correct port number in the conString.

Error: getaddrinfo ENOTFOUND people people:5432 at errnoException (dns.js:26:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)

This is my code so far:

8 Answers 8

If you’re sure your connection string is already well-formed like the one gnerkus described, the last thing you need to check is your password. If it’s contain non alphanumeric characters, maybe that’s the one who cause the issue. It seems either the Node.js or the way javascript work itself causing this (I’m not really sure since pg-admin can connect using my initial password just fine).

My password was contain ‘+’ and ‘/’ (acquired by creating a long json filled with gibberish and then hash it resulting base64 string) and I sure does receiving the same error like yours. Once I get rid of it (from my connection string and updating my database’s password), it’s working fine.

Oh, and . ‘=’ is accepted though. Because it seems the problem is with url decoding process at the database side. When I sent ‘+’ , I think it replaced by ‘ ‘ which will cause incorrect password. And the ‘/’ was causing malformed url which is the root cause of our error (which says not found). Take a look at this example.

I’m sure you’ll realize that there are extra ‘/’ which will cause wrong url break down. So, protocol:// user:pass@host / database changed into protocol:// [malformed user:pass@host] / [malformed database name] / [some gibberish] because of that extra ‘/’ .

If your colleague who access it using JSF can edit their connection string, I suggest to update the password to one which accepted by both. If they can’t, then you need to create another user/role with same access right but different password that can be used from Node.js.

EDIT: Or better yet, according to discussion here, try encode the password part of your connection string. They say it works. I didn’t bother to try it since I already change my password. Since you still has this issue, you might want to try it first before doing one of my two suggestions above.

Источник

Error: getaddrinfo ENOTFOUND when sending https request Node.js and API

I am developing a dashboard, I need to conect to a API and catch a Auth Token and afther that send info by using a HTTPS protocol. I use a Nodejs, and when I run my code I have the next error on the pm2 monit:

Also here is my code where I made the request (Node.js):

Here is the rest of the code:

3 Answers 3

Remove protocol, and use domain names only for the host. For instance:

See documentation for the http.request options.

It seems that is trying to getaddrinfo of the full url, instead of just the hostname. I would put hostname in option as only «my.url.net» and update path with the rest of the url.

@Eric0607 the error stackoverflow.com/questions/65810720/… you’ve provided is not showing anymore, I might’ve been too late to reply.

but in case you got «an invalid local cert SSL error«, here is a fix I found that works for it. disable SSL check in your code, not recommended but it would work temporarily, turn it on after you’re done or it can be risky.

Linked

Hot Network Questions

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.1.14.43159

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

«Error: getaddrinfo ENOTFOUND» error when making an HTTPs request

Part of AWS Collective

here’s the code in AWS Lambda function:

Error: getaddrinfo ENOTFOUND https://bittrex.com https://bittrex.com:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

Other solutions did not work.

4 Answers 4

Remove the https:// from the host. The require already says you’re using https/SSL.

I modified your code to work correctly in AWS Lambda Node.js 6.10. I set the Lambda timeout to be 60 seconds for testing.

The big change is adding «res.on(‘data’, function(chunk) <>:» and «res.on(‘end’, function() <>«.

The issue is with your security groups. Looks like your lambda doesn’t have access to resolve DNS. Check if you lambda sec groups have port 53 UDP and TCP enabled.

Also Make sure the lambda attempts to reach a reachable host. in other words make sure that the host doesn’t reside in a private network / VPN / or an unreachable network (that can’t be reached from the externally)

(Trivial but still worth mentioning)

This question is in a collective: a subcommunity defined by tags with relevant content and experts.

Источник

Error : getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443

I am working on a corporate network.

Trying to install npm. But I’m getting this error again and again.

Tried this also: npm config set registry https://registry.npmjs.org/

Still getting the same error.

17 Answers 17

  1. make sure you have internet connection: ping 8.8.8.8
  2. make sure you have DNS resolver working: ping www.google.com
  3. make sure you can access registry.npmjs.org: ping registry.npmjs.org
  4. make sure you can connect via https.

Make sure you are trying to connect to:

or some other weird string composed of few hostnames, because it’s weird that the resolver complains about a hostnames that includes a port number, which it shouldn’t care about. Ok, I tested and it should look like this for hosts that are not found.

Update

From your comment to this answer it seems that you are not directly connected to the internet if you can’t even ping 8.8.8.8.

If you are using a proxy to access the Web, then you also have to configure npm to use it. Use:

but instead of http://example.com:8080 use what you actually need in your company — ask someone or see how your browser is configured.

To see your proxy configuration in Chrome, see this.

Update 2

If you can access https://registry.npmjs.org/ in your browser but you cannot run ping registry.npmjs.org then it means that your browser must be configured to use a proxy, or other programs than your browser must be restricted from using the internet.

In any case, you should ask someone in your company about it because most likely you either need to use a specific proxy or someone needs to lift the restriction from your npm and allow it to access the network.

The network access can be blocked by a firewall installed on your computer or a router in your network. It’s hard to say without knowing the specific configuration in your company.

Update 3

Remove the environment variable «https_proxy» if any or use correct value for «https_proxy»

Источник

getaddrinfo ENOTFOUND api.telegram.org #99

This error every day. I think it’s because long plain. Maybe add live reload when exception?

The text was updated successfully, but these errors were encountered:

This problem makes the OS reboot

  • Upgrade your Node.js version (may overcome this error)
  • Flush your DNS
  • Reboot your machine (SO answer)

Please provide us with feedback.

I’m having a similar issue:

«node-telegram-bot-api»: «^0.24.0»,
npm -v 4.0.5
node -v v7.2.1

The nodejs application is running inside docker container, but it used to work nice until started raising this errors..

My bot is inside a Docker, I just stopped it and start again and everything was ok.

i have this issue all the time. restarting it does nothing because since i’ve got the latest version of node.js it completely shuts node down and the container goes down, so its constantly restarting all the time. network is bridged so it does have internet just fine. its its own container so dns cache shouldn’t even be a thing since containers are cleared upon reboot.

@dianjuar @MothGirlMusic not sure if you sorted your issue, but sometimes this ENOTFOUND issue is due to the underlying system not finding an IPv6 address for the host.

Some people report here adding family: 4 to the request() options does the trick (forces it to look for the IPv4 address, which should be findable).

It looks like request() options can be passed (see «request.options» on this page):

It’s actually still not solved after 6 years

if you are using docker try to restart it, it works fine with me after restarting docker service

I also get sometimes getaddrinfo EAI_AGAIN api.telegram.org , often after a system reboot. And yes my DNS resolver is correctly configured.

My guess is that Docker is actually starting-up faster the Docker container than my system network / DNS resolver is ready to handle the requests. Something like that.

My bet is that my systemd is missing requires network dependency (see: Requires: ) in the Docker service file:

Although I see that containerd.service requires network.target as dependency. Maybe this isn’t enough or on the wrong level or it should use network-online.target instead of network.target ? Or After=network-online.target Wants=network-online.target or maybe better: After=nss-lookup.target should be added.

Restarting the specific docker container manually always fixes the issue.

I already have a error handling, but it will not catch this getaddrinfo issue (so this code snipped will NOT help you):

Looking at the error traces, I suspect the request-promise package that throws this error. Which is used by in the internal function _request() .

Once you catched the getaddrinfo error, you can maybe set a global state in an error state. Add a health check to Docker, so Docker will automatically restart the Docker image to try again. Most likely this will be the best solution, since after a server reboot the Docker container is started before the DNS is ready. Restarting the Docker container only once would resolve the error for now.

@yagop Ideally the node-telegram-bot-api code should be robust for this error and have built-in a retry mechanism. So the bot doesn’t completely fail and stop working if this issue triggered only once.

Источник

kuchuluk

0 / 0 / 0

Регистрация: 05.02.2012

Сообщений: 24

1

19.07.2022, 09:20. Показов 630. Ответов 1

Метки javascript, node js, postgresql (Все метки)


Здравствуйте!
Нужно присоединиться к базе PostgreSQL через NodeJS.
Файл index.js:

Javascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require('dotenv').config()
const express = require('express')
const sequelize = require('./db')
const models = require('./models/models')
 
const PORT = process.env.PORT || 5000
 
const app = express()
 
 
const start = async () => {
    try {
        await sequelize.authenticate()
        await sequelize.sync()
        app.listen(PORT, () => console.log(`Server started on port ${PORT}`))
    } catch (e) {
        console.log(e)
    }
}
 
start()

файл db.js:

Javascript
1
2
3
4
5
6
7
8
9
10
11
12
const {Sequelize} = require('sequelize')
 
module.exports = new Sequelize(
    process.env.DB_NAME, // название БД
    process.env.DB_USER, // пользователь
    process.env.DB_PASSWORD, // пароль
    {
        dialect: 'postgres',
        host: process.env.DB_HOST,
        host: process.env.DB_PORT
    }
)

файл .env:

Код

PORT=5000
DB_NAME=online_store
DB_USER=postgres
DB_PASSWORD=root
DB_HOST=localhost
DB_PORT=5432

PostgreSQL установлена на компьютере, но вылезает в консоли ошибка:

Код

HostNotFoundError [SequelizeHostNotFoundError]: getaddrinfo ENOTFOUND 5432
at Client._connectionCallback (D:OpenServerdomainstestnodereact.localservernode_modulessequelizelibdialectspostgresconnection-manager.js:133:2
4)
at Client._handleErrorWhileConnecting (D:OpenServerdomainstestnodereact.localservernode_modulespglibclient.js:305:19)
at Client._handleErrorEvent (D:OpenServerdomainstestnodereact.localservernode_modulespglibclient.js:315:19)
at Connection.emit (events.js:400:28)
at Socket.reportStreamError (D:OpenServerdomainstestnodereact.localservernode_modulespglibconnection.js:52:12)
at Socket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
parent: Error: getaddrinfo ENOTFOUND 5432
parent: Error: getaddrinfo ENOTFOUND 5432
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:71:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: '5432'
},
original: Error: getaddrinfo ENOTFOUND 5432
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:71:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: '5432'
}
}

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



Ищу работу React

814 / 620 / 212

Регистрация: 17.07.2021

Сообщений: 1,336

Записей в блоге: 7

19.07.2022, 13:09

2

Лучший ответ Сообщение было отмечено kuchuluk как решение

Решение

Надо несколько очков скила на внимательность кинуть

Код

        host: process.env.DB_HOST,
        host: process.env.DB_PORT

второй параметр должен port по логике документацию не смотрел

Код

host: process.env.DB_HOST,
port: process.env.DB_PORT



2



I’m new to pretty much all these technologies; node, react, postgres, docker, etc. but I started a small/medium size project using them all. Everything I’ve learned is self-taught so any feedback or improvements would be greatly appreciated. I was running the project locally and the start of the project worked fine but now I’m trying to dockerize the project and getting a little stumped.

Here is my docker-compose.yml file:

version: '3.7'
services:
  postgres:
    image: postgres:11-alpine
    ports:
      - 5432:5432
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=project_database
#    network_mode: 'host'
    restart: always
  react:
    build: ./client
    ports:
      - 3000:3000
    volumes:
      - ./client:/app
      - /app/node_modules
    environment:
      - NODE_ENV=development
    restart: always
  node:
    build: ./server
    ports:
      - 3001:3001
    volumes:
      - ./server:/app
      - /app/node_modules
    environment:
      - NODE_ENV=development
    depends_on:
      - postgres
    links:
      - postgres:postgres
    restart: always
#  nginx: 
#    image: nginx:1.15-alpine
#    ports:
#      - 8080:80
#    volumes:
#      - /docker/nginx.conf:/etc/nginx/conf.d/default.conf
#    links:
#      - frontend
#      - backend

This is my Node Dockerfile:

FROM node:10-alpine

RUN apk update && apk upgrade
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

RUN mkdir /app
WORKDIR /app

COPY package*.json .
RUN npm install yarn -g
RUN apk --no-cache add --virtual builds-deps build-base python
RUN yarn install
#RUN npm rebuild bcrypt --build-from-source
COPY . .
RUN yarn setup

EXPOSE 3001
CMD yarn start

This is my React Dockerfile:

FROM node:10-alpine

RUN apk update && apk upgrade
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

RUN mkdir /app
WORKDIR /app

COPY package*.json .
RUN npm install yarn -g
RUN yarn install
RUN npm install react-scripts -g
COPY . .

EXPOSE 3000
CMD yarn start

The problem is the RUN yarn setup is supposed to run database migrations and seeds but I either get «ERROR: getaddrinfo ENOTFOUND postgres postgres:5432» or «ERROR: connect ECONNREFUSED 127.0.0.1:5432». I’m not sure what I’m doing wrong. Any resources to help resolve this issue would be greatly appreciated! Thanks in advance!

For reference, I did try to look at these two projects for answers but it didn’t help much because I’m still stuck getting those errors. https://github.com/aldrichvalentino/node-postgres
https://github.com/raunofreiberg/blackford

Понравилась статья? Поделить с друзьями:
  • Error get class hints
  • Error get alias что это
  • Error get alias тильда
  • Error get alias перевод
  • Error get alias tilda ошибка