Problem with NATS server from Docker image

Project ID: cd4ba81b-6c4a-4395-ab96-6db05d8eed0f Hi everyone. I'm facing another error with my docker project. I have deployed a NATS server from a Docker image. It is working fine, but when I try to connect from other services they answer with a Timeout. I have tried with the private url, the public one and some other urls but it doesn't work. Also tried to increase the timeout time, but it neither works. Can anyone help me? This is the full error: piccola-launcher-orders-ms-1 | /usr/src/app/node_modules/nats/lib/nats-base-client/core.js:140 piccola-launcher-orders-ms-1 | return new NatsError(m, code, chainedError); piccola-launcher-orders-ms-1 | ^ piccola-launcher-orders-ms-1 | piccola-launcher-orders-ms-1 | NatsError: TIMEOUT piccola-launcher-orders-ms-1 | at NatsError.errorForCode (/usr/src/app/node_modules/nats/lib/nats-base-client/core.js:140:16) piccola-launcher-orders-ms-1 | at timeout (/usr/src/app/node_modules/nats/lib/nats-base-client/util.js:57:48) piccola-launcher-orders-ms-1 | at ProtocolHandler. (/usr/src/app/node_modules/nats/lib/nats-base-client/protocol.js:415:44) piccola-launcher-orders-ms-1 | at Generator.next () piccola-launcher-orders-ms-1 | at /usr/src/app/node_modules/nats/lib/nats-base-client/protocol.js:8:71 piccola-launcher-orders-ms-1 | at new Promise () piccola-launcher-orders-ms-1 | at __awaiter (/usr/src/app/node_modules/nats/lib/nats-base-client/protocol.js:4:12) piccola-launcher-orders-ms-1 | at ProtocolHandler.dial (/usr/src/app/node_modules/nats/lib/nats-base-client/protocol.js:411:16) piccola-launcher-orders-ms-1 | at ProtocolHandler. (/usr/src/app/node_modules/nats/lib/nats-base-client/protocol.js:480:32) piccola-launcher-orders-ms-1 | at Generator.next () { piccola-launcher-orders-ms-1 | code: 'TIMEOUT', piccola-launcher-orders-ms-1 | chainedError: undefined piccola-launcher-orders-ms-1 | } piccola-launcher-orders-ms-1 | piccola-launcher-orders-ms-1 | Node.js v21.7.3
Solution:
if you try to make a connection to nats at the very start of your app, you will need to add a 3 second sleep before you start your app
Jump to solution
19 Replies
Percy
Percy7mo ago
Project ID: cd4ba81b-6c4a-4395-ab96-6db05d8eed0f
Brody
Brody7mo ago
can you show me some of the connection URLs you've tried?
antogonza1
antogonza1OP7mo ago
Don’t have them right now, but are something like: nats://publicUrl:4222 nats://privateUrl:4222 nats://publicUrl https://publicUrl:4222
Brody
Brody7mo ago
none of those would work for use with the public url - - https only - port 443 only what urls did you try with the private domain?
antogonza1
antogonza1OP7mo ago
The private domain is nats.railway.internal. How should it be? https://nats.railway.internal:443 ? But how can I specify the port for client connections, monitor…?
Brody
Brody7mo ago
for private URLs you need to be using a non secure schema and specifying the port in the url
antogonza1
antogonza1OP7mo ago
So it would be http://nats.railway.internal:443 , right?
Brody
Brody7mo ago
i assume nats runs on port 4222, so you would want to use port 4222
antogonza1
antogonza1OP7mo ago
It doesn’t work… now I have this error: node:internal/process/promises:289 triggerUncaughtException(err, true /* fromPromise */); ^ Error: getaddrinfo ENOTFOUND nats.railway.internal at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) { errno: -3008, code: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'nats.railway.internal' } Node.js v21.7.3
Brody
Brody7mo ago
are the two services in the same project? they need to be
antogonza1
antogonza1OP7mo ago
Brody
Brody7mo ago
at what point in your apps lifecycle does your app try to connect to nats
antogonza1
antogonza1OP7mo ago
At the beginning. It does not even start. Here is the complete log: [Nest] 7 - 05/18/2024, 4:08:39 PM LOG [NestFactory] Starting Nest application... [Nest] 7 - 05/18/2024, 4:08:39 PM LOG [InstanceLoader] AppModule dependencies initialized +18ms [Nest] 7 - 05/18/2024, 4:08:39 PM LOG [InstanceLoader] NatsModule dependencies initialized +0ms [Nest] 7 - 05/18/2024, 4:08:39 PM LOG [InstanceLoader] ClientsModule dependencies initialized +1ms [Nest] 7 - 05/18/2024, 4:08:39 PM LOG [InstanceLoader] OrdersModule dependencies initialized +1ms [Nest] 7 - 05/18/2024, 4:08:39 PM DEBUG [OrdersService] Connected Database node:internal/process/promises:289 triggerUncaughtException(err, true /* fromPromise */); ^ Error: getaddrinfo ENOTFOUND nats.railway.internal at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) { errno: -3008, code: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'nats.railway.internal' } Node.js v21.7.3 It should show a debug log with “Microservice started on port “ when it’s finally started
Solution
Brody
Brody7mo ago
if you try to make a connection to nats at the very start of your app, you will need to add a 3 second sleep before you start your app
antogonza1
antogonza1OP7mo ago
But I have my NATS server running, I’m just trying to launch different services. Should I also add the initialization time?
Brody
Brody7mo ago
yes, you need to delay the start of the app that is connecting to it, please read the docs section
antogonza1
antogonza1OP7mo ago
Yes, I already read it. I’ll try asap. Thank you very much! It worked @Brody , you're the best!
Brody
Brody7mo ago
no problem!
Want results from more Discord servers?
Add your server