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:Jump to 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
19 Replies
Project ID:
cd4ba81b-6c4a-4395-ab96-6db05d8eed0f
can you show me some of the connection URLs you've tried?
Don’t have them right now, but are something like:
nats://publicUrl:4222
nats://privateUrl:4222
nats://publicUrl https://publicUrl:4222
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?
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…?
for private URLs you need to be using a non secure schema and specifying the port in the url
i assume nats runs on port 4222, so you would want to use port 4222
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
are the two services in the same project? they need to be
Yes it is. I used http://nats.railway.internal:4222
at what point in your apps lifecycle does your app try to connect to nats
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
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
But I have my NATS server running, I’m just trying to launch different services. Should I also add the initialization time?
yes, you need to delay the start of the app that is connecting to it, please read the docs section
Yes, I already read it. I’ll try asap. Thank you very much!
It worked @Brody , you're the best!
no problem!