Skip to content
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

NATS server disconnecting randomly #620

Closed
4 tasks done
knvpk opened this issue Nov 16, 2019 · 24 comments · Fixed by #633
Closed
4 tasks done

NATS server disconnecting randomly #620

knvpk opened this issue Nov 16, 2019 · 24 comments · Fixed by #633
Labels

Comments

@knvpk
Copy link

knvpk commented Nov 16, 2019

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the 0.13.11 version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed
  • I'm reporting the issue to the correct repository (May be it belongs to NATS repository I don't know)

Current Behavior

Im using the transporter NATS option by keeping the config as transporter: "NATS", But while coding in vscode and hotreloading sometimes NATS server is disconnecting and saying the error as Invalid subject, but again changing the some code and hot reloading it is reconnecting successfully. Actually this can be ok in development , but we are using docker deployment there is no option for hot-reloading option so that NATS can reconnect again.

Expected Behavior

While coding and hot reloading the NATS server should stay connected always.

Failure Information

Please check the image for more error info
nats

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. init project with moleculer cli
  2. added 2 or more services
  3. Use NATS as transporter
  4. Try to change code and do hot-reloads

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Moleculer version:0.13.11
  • NodeJS version: 8.12.0
  • Operating System: Ubuntu 19.04
@knvpk knvpk changed the title NATS server disconnected randomly NATS server disconnecting randomly Nov 16, 2019
@icebob
Copy link
Member

icebob commented Nov 16, 2019

Are you using NATS client with pedantic option?

@knvpk
Copy link
Author

knvpk commented Nov 16, 2019

No, im not giving any external options for NATS server
I installed the nats server from this page https://github.com/nats-io/nats-server/releases/tag/v2.1.0 and in Assets using amd64.deb file and every time i just issue nats-server command. the out put will be like

[27788] 2019/11/16 17:29:04.823411 [INF] Starting nats-server version 2.1.0
[27788] 2019/11/16 17:29:04.823472 [INF] Git commit [1cc5ae0]
[27788] 2019/11/16 17:29:04.823790 [INF] Listening for client connections on 0.0.0.0:4222
[27788] 2019/11/16 17:29:04.823804 [INF] Server id is ND3MCWQTI4FG5PGKZD2M47OW5XRTMDGYJS736HJTMHZ6RBRIKB7QO6BR
[27788] 2019/11/16 17:29:04.823814 [INF] Server is ready

And in docker-compose.yml i use the nats docker image as below

  nats:
    image: nats:latest
    ports:
      - "4222:4222"

@knvpk
Copy link
Author

knvpk commented Nov 16, 2019

For more info:
I just kept log level to debug in moleculerjs config then i got this out put

[2019-11-16T12:22:17.331Z] DEBUG 088922e1243d-19/TRANSPORTER: { NatsError: 'Invalid Subject'
at Client.processErr (/app/node_modules/nats/lib/nats.js:1389:28)
at Client.processInbound (/app/node_modules/nats/lib/nats.js:1118:30)
at Socket.stream.on (/app/node_modules/nats/lib/nats.js:738:14)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:287:12)
at readableAddChunk (_stream_readable.js:268:11)
at Socket.Readable.push (_stream_readable.js:223:10)
 at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) name: 'NatsError', message: '\'Invalid Subject\'', code: 'NATS_PROTOCOL_ERR', chainedError: undefined }

@icebob
Copy link
Member

icebob commented Nov 16, 2019

It's weird. I've checked the source code of NATS and it seems it throws this error if pedantic is enabled and some client publish a topic which has no subscriber.

@knvpk
Copy link
Author

knvpk commented Nov 16, 2019

May be pendantic is enabled by default, can you tell me how to disable that.

@icebob
Copy link
Member

icebob commented Nov 16, 2019

try it in moleculer.config.js

module.exports = {
    transporter: {
        type: "NATS",
        options: {
            url: "nats://localhost:4222",
            pedantic: false
        }
    }
}

@knvpk
Copy link
Author

knvpk commented Nov 17, 2019

@icebob , I checked with that configuration, but still error is coming.

[2019-11-17T03:57:33.036Z] WARN  mylaptop-6560/TRANSPORTER: NATS client is reconnecting...
[2019-11-17T03:57:33.068Z] ERROR mylaptop-6560/TRANSPORTER: NATS error. 'Invalid Subject'
[2019-11-17T03:57:35.071Z] WARN  mylaptop-6560/TRANSPORTER: NATS client is reconnecting...
[2019-11-17T03:57:35.074Z] ERROR mylaptop-6560/TRANSPORTER: NATS error. 'Invalid Subject'
[2019-11-17T03:57:37.075Z] WARN  mylaptop-6560/TRANSPORTER: NATS client is reconnecting...
[2019-11-17T03:57:37.078Z] ERROR mylaptop-6560/TRANSPORTER: NATS error. 'Invalid Subject'
[2019-11-17T03:57:39.079Z] WARN  mylaptop-6560/TRANSPORTER: NATS client is reconnecting...
[2019-11-17T03:57:39.084Z] ERROR mylaptop-6560/TRANSPORTER: NATS error. 'Invalid Subject'
[2019-11-17T03:57:41.087Z] WARN  mylaptop-6560/TRANSPORTER: NATS client is reconnecting...
[2019-11-17T03:57:41.090Z] ERROR mylaptop-6560/TRANSPORTER: NATS error. 'Invalid Subject'
[2019-11-17T03:57:43.092Z] WARN  mylaptop-6560/TRANSPORTER: NATS client is reconnecting...
[2019-11-17T03:57:43.096Z] ERROR mylaptop-6560/TRANSPORTER: NATS error. 'Invalid Subject'
[2019-11-17T03:57:45.098Z] WARN  mylaptop-6560/TRANSPORTER: NATS client is reconnecting...
[2019-11-17T03:57:45.101Z] ERROR mylaptop-6560/TRANSPORTER: NATS error. 'Invalid Subject'
[2019-11-17T03:57:47.104Z] WARN  mylaptop-6560/TRANSPORTER: NATS client is reconnecting...
[2019-11-17T03:57:47.107Z] ERROR mylaptop-6560/TRANSPORTER: NATS error. 'Invalid Subject'
^C[2019-11-17T03:57:49.108Z] WARN  mylaptop-6560/TRANSPORTER: NATS client is reconnecting...

@knvpk
Copy link
Author

knvpk commented Nov 17, 2019

These are the logs from NATS server side

[6625] 2019/11/17 09:29:44.532738 [INF] Starting nats-server version 2.0.0
[6625] 2019/11/17 09:29:44.532833 [DBG] Go build version go1.11.10
[6625] 2019/11/17 09:29:44.532852 [INF] Git commit [not set]
[6625] 2019/11/17 09:29:44.533065 [INF] Listening for client connections on 0.0.0.0:4222
[6625] 2019/11/17 09:29:44.533083 [INF] Server id is NBWAVSBAJEQRATEJYY6HPGD5LU3WGMSGIBDPWQLETTL2S7NSYUQ6YYQF
[6625] 2019/11/17 09:29:44.533094 [INF] Server is ready
[6625] 2019/11/17 09:29:44.533109 [DBG] Get non local IPs for "0.0.0.0"
[6625] 2019/11/17 09:29:44.533739 [DBG]  ip=192.168.0.109
[6625] 2019/11/17 09:29:44.533834 [DBG]  ip=172.18.0.1
[6625] 2019/11/17 09:29:44.533922 [DBG]  ip=172.19.0.1
[6625] 2019/11/17 09:29:44.534013 [DBG]  ip=172.17.0.1
[6625] 2019/11/17 09:29:49.789085 [DBG] 127.0.0.1:46532 - cid:1 - Client connection created
[6625] 2019/11/17 09:29:53.158434 [DBG] 127.0.0.1:46532 - cid:1 - Client connection closed
[6625] 2019/11/17 09:29:55.162385 [DBG] 127.0.0.1:46560 - cid:2 - Client connection created
[6625] 2019/11/17 09:29:55.165186 [DBG] 127.0.0.1:46560 - cid:2 - Client connection closed
[6625] 2019/11/17 09:29:57.167634 [DBG] 127.0.0.1:46562 - cid:3 - Client connection created
[6625] 2019/11/17 09:29:57.169971 [DBG] 127.0.0.1:46562 - cid:3 - Error flushing: writev tcp 127.0.0.1:4222->127.0.0.1:46562: writev: connection reset by peer
[6625] 2019/11/17 09:29:57.170014 [DBG] 127.0.0.1:46562 - cid:3 - Client connection closed
[6625] 2019/11/17 09:29:59.173343 [DBG] 127.0.0.1:46564 - cid:4 - Client connection created
[6625] 2019/11/17 09:29:59.175506 [DBG] 127.0.0.1:46564 - cid:4 - Error flushing: writev tcp 127.0.0.1:4222->127.0.0.1:46564: writev: connection reset by peer
[6625] 2019/11/17 09:29:59.175677 [DBG] 127.0.0.1:46564 - cid:4 - Client connection closed
[6625] 2019/11/17 09:30:01.179409 [DBG] 127.0.0.1:46566 - cid:5 - Client connection created
[6625] 2019/11/17 09:30:01.181779 [DBG] 127.0.0.1:46566 - cid:5 - Client connection closed
[6625] 2019/11/17 09:30:03.184111 [DBG] 127.0.0.1:46568 - cid:6 - Client connection created
[6625] 2019/11/17 09:30:03.186558 [DBG] 127.0.0.1:46568 - cid:6 - Error flushing: writev tcp 127.0.0.1:4222->127.0.0.1:46568: writev: connection reset by peer

@icebob
Copy link
Member

icebob commented Nov 17, 2019

Thanks, please try it with the latest NATS server 2.1.0, as well.

@icebob icebob added Module: Transporter Status: Need reproduce Issue waits for reproducing labels Nov 17, 2019
@knvpk
Copy link
Author

knvpk commented Nov 18, 2019

Same error with NATS 2.1.0 also

[3326] 2019/11/18 09:52:06.771147 [INF] Starting nats-server version 2.1.0
[3326] 2019/11/18 09:52:06.771274 [DBG] Go build version go1.12.9
[3326] 2019/11/18 09:52:06.771284 [INF] Git commit [1cc5ae0]
[3326] 2019/11/18 09:52:06.771685 [INF] Listening for client connections on 0.0.0.0:4222
[3326] 2019/11/18 09:52:06.771705 [INF] Server id is NAGSPDMONL73TIUQIZLL7U547B5DPZOKBAFZTSZRE5AQA5LOFMRJYOV6
[3326] 2019/11/18 09:52:06.771714 [INF] Server is ready
[3326] 2019/11/18 09:52:06.771727 [DBG] Get non local IPs for "0.0.0.0"
[3326] 2019/11/18 09:52:06.772267 [DBG]  ip=192.168.0.12
[3326] 2019/11/18 09:52:06.772355 [DBG]  ip=172.18.0.1
[3326] 2019/11/18 09:52:06.772432 [DBG]  ip=172.19.0.1
[3326] 2019/11/18 09:52:06.772508 [DBG]  ip=172.17.0.1
[3326] 2019/11/18 09:54:32.510493 [DBG] 127.0.0.1:43568 - cid:1 - Client connection created
[3326] 2019/11/18 09:54:39.520810 [DBG] 127.0.0.1:43568 - cid:1 - Client connection closed
[3326] 2019/11/18 09:54:41.524456 [DBG] 127.0.0.1:43598 - cid:2 - Client connection created
[3326] 2019/11/18 09:54:41.527204 [DBG] 127.0.0.1:43598 - cid:2 - Client connection closed
[3326] 2019/11/18 09:54:43.529903 [DBG] 127.0.0.1:43600 - cid:3 - Client connection created
[3326] 2019/11/18 09:54:43.532129 [DBG] 127.0.0.1:43600 - cid:3 - Error flushing: writev tcp 127.0.0.1:4222->127.0.0.1:43600: writev: connection reset by peer
[3326] 2019/11/18 09:54:43.532265 [DBG] 127.0.0.1:43600 - cid:3 - Client connection closed
[3326] 2019/11/18 09:54:45.533725 [DBG] 127.0.0.1:43602 - cid:4 - Client connection created
[3326] 2019/11/18 09:54:45.535888 [DBG] 127.0.0.1:43602 - cid:4 - Client connection closed
[3326] 2019/11/18 09:54:47.539372 [DBG] 127.0.0.1:43604 - cid:5 - Client connection created
[3326] 2019/11/18 09:54:47.541674 [DBG] 127.0.0.1:43604 - cid:5 - Client connection closed
[3326] 2019/11/18 09:54:49.544227 [DBG] 127.0.0.1:43610 - cid:6 - Client connection created
[3326] 2019/11/18 09:54:49.546708 [DBG] 127.0.0.1:43610 - cid:6 - Client connection closed

@icebob
Copy link
Member

icebob commented Nov 19, 2019

But it happens when you hotreload a service, right?

@knvpk
Copy link
Author

knvpk commented Nov 20, 2019

I will tell you clearly

When ever i start the project using npm run dev, after all services loaded these errors are coming, then i will go to one of the service file any_one_of.service.ts file click save, then it will hot reload and reconnect.... Also randomly it disconnects again then again i need to click save for any one of the service file so it reconnects

@icebob
Copy link
Member

icebob commented Nov 20, 2019

very very strange. Could you make a video about it? :)

@knvpk
Copy link
Author

knvpk commented Dec 12, 2019

Hi @icebob , I have sent you mail with screen recording video please check once.

@knvpk
Copy link
Author

knvpk commented Dec 14, 2019

Hi @icebob , Debugging in depth i found the actual line of code which is causing this problem i think it will help to find out actual error.

We are actually using the your kantab project config mixin along with config service, in that config mixin if we comment the events line then this problem is not coming.

@icebob
Copy link
Member

icebob commented Dec 15, 2019

Hmm, it means, the event name contains some prohibited character. Could you print out the events object to the console. to see the event names?

@knvpk
Copy link
Author

knvpk commented Dec 16, 2019

These are the possible event names form different services

From accounts service:

{
  'config.site.**.changed': [Function: eventHandler],
  'config.mail.**.changed': [Function: eventHandler],
  'config.accounts.**.changed': [Function: eventHandler]
}

From mail service:

{
  'config.site.**.changed': [Function: eventHandler],
  'config.mail.**.changed': [Function: eventHandler]
}

These accounts and mails service is from your repository only.

@icebob
Copy link
Member

icebob commented Dec 16, 2019

I have no idea. Could you create a small reproduce repo?

@icebob
Copy link
Member

icebob commented Dec 16, 2019

Not need it. I can reproduce.

AndreMaz added a commit to AndreMaz/moleculer that referenced this issue Dec 17, 2019
AndreMaz added a commit that referenced this issue Dec 17, 2019
@icebob
Copy link
Member

icebob commented Dec 17, 2019

Released in 0.13.12

@roonie007
Copy link

@icebob is this fix available in 0.14.0 ?

@knvpk
Copy link
Author

knvpk commented Dec 27, 2019

Hi @icebob , i installed 0.13.12 and it working fine now.

@AndreMaz
Copy link
Member

AndreMaz commented Dec 27, 2019

@roonie007 it's not available it latest beta 0.14.0-beta6. But you can use it by installing directly from github (next branch) with npm i moleculerjs/moleculer

@icebob
Copy link
Member

icebob commented Jan 9, 2020

Released in 0.14.0-beta7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants