pnxtech / hydra-router

A service aware router for Hydra Services. Implements an API Gateway and can route web socket messages.
MIT License
60 stars 24 forks source link

hydra-router require guarantee of running node during route match #86

Open jkyberneees opened 7 years ago

jkyberneees commented 7 years ago

The router seems to be accepting the first URL match without guarantee that such service have a running node instance. In my case I just started a hapi-service-test service and the response from the router is this:

{
 "statusCode": 503,
 "statusMessage": "Service Unavailable",
 "statusDescription": "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay",
 "result": {
   "reason": "HR: [ol0r2s8oml] Unavailable express-service-test instances"
 },
 "tracer": "ol0r2s8oml"
}

Meaning that the hydra-router is considering old routes from the express-service-test service that I have ran in the past.

Regards, Rolando

cjus commented 7 years ago

@jkyberneees on startup, your hapi-service-test should have sent a message to hydra-router with its updated routes.

jkyberneees commented 7 years ago

Hi @cjus, it does it. However the issue appears when multiple services have registered the same route. IMO the router should decide for the service that match the route but also is online.

cjus commented 7 years ago

@jkyberneees I looked into this. I don't see a way to address it. I think it's up to the service builder to ensure that routes are not reused by other services. Meaning two different services should not both register v1/{serviceName}/endpoint. I also think that service registries have to expire at some point. Perhaps a router that ends up with a 503 might flush the service registry or perhaps a Lua script in Redis.

jkyberneees commented 7 years ago

Hi @cjus, I can suggest you to check for service presence before accept the route match. You can see an example here: https://github.com/jkyberneees/hydra-plugin-http/blob/master/libs/proxy.js#L35 I agree on the flush of the routes if 503 is detected, that would keep the router more performant and consistent.

Regards.

arn-the-long-beard commented 6 years ago

Hello This discussion is old, but I have the same issue with hydra-router.

I used the different command for clean and refresh: hydra-cli refresh hydra-cli refresh node list

but hydra-cli routes show me the old dead services and then hydra-router cannot work correctly.

Is it something I am missing for cleaning/refresh ?

cjus commented 6 years ago

@arn-the-long-beard which version of hydra-cli are you using? How comfortable are you with Redis? Is this happening locally or on a production server?

arn-the-long-beard commented 6 years ago

Hello @cjus :)

I am using hydra-cli@1.5.5

For now this is happening locally. I am a very newbie to Hydra and Redis also. I am building micro services for a distributed system for the startup I am working.

emirhg commented 5 years ago

Same problem here. I'm using hydra-cli@1.6.0

hydra-cli refresh and hydra-cli refresh node listkeeps old routes, is not cleaning properly