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

When to initialized the library #46

Closed
dekelev opened this issue Jan 13, 2020 · 3 comments
Closed

When to initialized the library #46

dekelev opened this issue Jan 13, 2020 · 3 comments

Comments

@dekelev
Copy link

dekelev commented Jan 13, 2020

It is unclear when the feathers-distributed library should be initialized. the docs suggest to do that after app(hooks). does it means that it must be initialized after initializing all the services?

I've tried initializing at the end of the bootstrap and had no issues. Then I've tried initializing it before the services and before the authentication service initialization and got this error due to issue with the authentication service publishing:

TypeError [ERR_INVALID_ARG_TYPE]: The "options.port" property must be one of type number or string. Received type object
    at lookupAndConnect (net.js:960:13)
    at Socket.connect (net.js:940:5)
    at SubSocket.Socket.connect (/opt/app/node_modules/@dashersw/axon/lib/sockets/sock.js:297:8)
    at Subscriber.onAdded (/opt/app/node_modules/cote/dist/components/subscriber.js:53:15)
    at Discovery.discovery.on.obj (/opt/app/node_modules/cote/dist/components/component.js:30:12)
    at Discovery.emit (events.js:187:15)
    at Discovery.EventEmitter.emit (domain.js:442:20)
    at Network.Discover.self.evaluateHello (/opt/app/node_modules/@dashersw/node-discover/lib/discover.js:176:9)
    at Network.emit (events.js:182:13)
    at Network.EventEmitter.emit (domain.js:442:20)
    at /opt/app/node_modules/@dashersw/node-discover/lib/network.js:72:22
    at Network.decode (/opt/app/node_modules/@dashersw/node-discover/lib/network.js:208:12)
    at Socket.<anonymous> (/opt/app/node_modules/@dashersw/node-distscover/lib/network.js:53:14)
    at Socket.emit (events.js:182:13)
    at Socket.EventEmitter.emit (domain.js:442:20)
    at RedisClient.<anonymous> (/opt/app/node_modules/@dashersw/node-discover/lib/redis.js:22:14)
    at RedisClient.emit (events.js:182:13)
    at RedisClient.EventEmitter.emit (domain.js:442:20)
    at return_pub_sub (/opt/app/node_modules/redis/index.js:790:18)
    at RedisClient.return_reply (/opt/app/node_modules/redis/index.js:833:9)
    at JavascriptRedisParser.returnReply (/opt/app/node_modules/redis/index.js:192:18)
    at JavascriptRedisParser.execute (/opt/app/node_modules/redis-parser/lib/parser.js:574:12)
    at Socket.<anonymous> (/opt/app/node_modules/redis/index.js:274:27)
    at Socket.emit (events.js:182:13)
    at Socket.EventEmitter.emit (domain.js:442:20)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)

After some debugging, it seems that the server was trying to connect to host with port null.

@claustres
Copy link
Member

claustres commented Jan 13, 2020

There are different things at play here about the initialization orders. I will try to be exhaustive and any help on this is much appreciated.

  1. The library overrides app.use() to automatically publish any new service defined, so that you can usually safely initialize it before registering your services like others feathers plugins (transport, configuration, etc.). However, you might also configure some middlewares with options.middlewares (Ability to add middlewares to remote services #26) and in this case you probably need to initialize the express plugin beforehand.

  2. The library also tries to immediately initialize the underlying cote module unless you intentionally add some delay. This delay can be required because it appears that in some scenarios (e.g. Docker deployment Initialization delay before starting cote #36) the network setup takes some time and cote is not able to correctly initialize (e.g. allocate ports) before. The error you have seems to be of this type, I guess cote did not find any open port on the host because network is not yet configured correctly.

  3. As the library also relies on cote components to publish/subscribe events, and these components take some time to initialize, there is also a publication delay that is respected before publishing app services.

I am not completely happy with all of this and any way to improve is welcomed.

@dekelev
Copy link
Author

dekelev commented Jan 13, 2020

Interesting, I'll give it a thought.

I did debugged portfinder when I had this issue and noticed that it fails to bind on port the should be available and so on with the next ports, without success. that's probably because the network was somehow not ready yet as you mentioned.

@claustres
Copy link
Member

I've just added a tips section in docs so I propose to close this issue, please reopen for anything that looks like a bug.

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

No branches or pull requests

2 participants