moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
291 stars 119 forks source link

autoAliases and routes specification update #295

Closed furanzujin closed 2 years ago

furanzujin commented 2 years ago

Hello,

We are using the autoAliases feature provided by moleculer-web. We have experienced some unexpected behavior with regenerateAllAutoAliases.

Working scenario:

  1. the instance of the service with the old route definition is disconnected
  2. the new instance is started
  3. the action is available on the new route

Failing scenario:

  1. the new instance is started
  2. the instance of the service with the old route definition is disconnected
  3. the action is unavailable on the new route (but still available on the old route)

The regenerateAllAutoAliases is based on the moleculer registry. The moleculer registry is updated once the node is disconnected but the autoAliases are not regenerated right after that.

We believe this behavior is intentional to avoid early revocation of the previous paths. Do you confirm this?

As we don't use routes versioning, we implemented a workaround. We subscribe to the $node.disconnected event to trigger a new execution of the regenerateAllAutoAliases method. Do you think there are caveats with this implementation? Is there any better way to do this?

icebob commented 2 years ago

The alias regenerate is triggered by the $services.changed internal event which is fired when the service registry is changed. So if you have a ServiceA which is running on 3 nodes, and 1 node disconnected, the service registry is not changed, because ServiceA is still available, no need for a regeneration. So it's by design. Your use case is not a normal production case when a service is available in different schemas with the same version number.

To cover your use case your solution could be good. But I won't add it to the moleculer-web because in a normal use case it can't cause a problem.

furanzujin commented 2 years ago

@icebob , Thanks for your fast answer. We will keep our solution as it has been implemented.