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

Ocelot returns 500 from Consul for the first request #1294

Closed
chaitanyaphanikumar opened this issue Jul 20, 2020 · 3 comments · Fixed by #1670
Closed

Ocelot returns 500 from Consul for the first request #1294

chaitanyaphanikumar opened this issue Jul 20, 2020 · 3 comments · Fixed by #1670
Assignees
Labels
bug Identified as a potential bug merged Issue has been merged to dev and is waiting for the next release Service Discovery Ocelot feature: Service Discovery

Comments

@chaitanyaphanikumar
Copy link

chaitanyaphanikumar commented Jul 20, 2020

I have registered 3 services in Consul. (IdentityService is one of them). While trying to access this service through Ocelot, I had the below exception and Postman response returned 500 Internal server error.

Second request to this service returned 503 Service Unavailable.

Third request was Success and returned 200 OK.

Did I miss something to configure ?

Ocelot Configuration.json

{
"DownstreamPathTemplate": "/api/v1/identity/register",
"DownstreamScheme": "https",
"UseServiceDiscovery": true,
"ServiceName": "IdentityService",
"UpstreamPathTemplate": "/v1/identity/register",
"UpstreamHttpMethod": [ "POST" ],
"LoadBalancerOptions": {
"Type": "LeastConnection"
}
}
],
"GlobalConfiguration": {
"RequestIdKey": "OcRequestId",
"BaseUrl": "https://localhost:44311",
"ServiceDiscoveryProvider": {
"Scheme": "http",
"Host": "localhost",
"Port": 8500,
"Type": "Consul"
}
}

Exception (500 Reponse):-

Consul.ConsulRequestException: Unexpected response, status code ServiceUnavailable:

ERROR

The requested URL could not be retrieved

The following error was encountered while trying to retrieve the URL: http://localhost:8500/v1/health/service/IdentityService

Connection to ::1 failed.

The system returned: (111) Connection refused

The remote host or network may be down. Please try the request again.

Your cache administrator is webmaster.



at Consul.GetRequest`1.Execute(CancellationToken ct)
at Ocelot.Provider.Consul.Consul.Get()
at Ocelot.LoadBalancer.LoadBalancers.LoadBalancerFactory.<>c__DisplayClass2_0.<b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Ocelot.LoadBalancer.LoadBalancers.LeastConnection.Lease(DownstreamContext downstreamContext)
at Ocelot.LoadBalancer.Middleware.LoadBalancingMiddleware.Invoke(DownstreamContext context)
at Ocelot.QueryStrings.Middleware.ClaimsToQueryStringMiddleware.Invoke(DownstreamContext context)
at Ocelot.Headers.Middleware.ClaimsToHeadersMiddleware.Invoke(DownstreamContext context)
at Ocelot.Authorisation.Middleware.AuthorisationMiddleware.Invoke(DownstreamContext context)
at Ocelot.Claims.Middleware.ClaimsToClaimsMiddleware.Invoke(DownstreamContext context)
at Ocelot.Authentication.Middleware.AuthenticationMiddleware.Invoke(DownstreamContext context)
at Ocelot.RequestId.Middleware.ReRouteRequestIdMiddleware.Invoke(DownstreamContext context)
at Ocelot.RateLimit.Middleware.ClientRateLimitMiddleware.Invoke(DownstreamContext context)
at Ocelot.Request.Middleware.DownstreamRequestInitialiserMiddleware.Invoke(DownstreamContext context)
at Ocelot.Headers.Middleware.HttpHeadersTransformationMiddleware.Invoke(DownstreamContext context)
at Ocelot.Security.Middleware.SecurityMiddleware.Invoke(DownstreamContext context)
at Ocelot.Middleware.Multiplexer.Multiplexer.Fire(DownstreamContext context, OcelotRequestDelegate next)
at Ocelot.Middleware.Multiplexer.Multiplexer.Multiplex(DownstreamContext context, ReRoute reRoute, OcelotRequestDelegate next)
at Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware.Invoke(DownstreamContext context)
at Ocelot.Responder.Middleware.ResponderMiddleware.Invoke(DownstreamContext context)
at Ocelot.Middleware.Pipeline.MapWhenMiddleware.Invoke(DownstreamContext context)
at Ocelot.Errors.Middleware.ExceptionHandlerMiddleware.Invoke(DownstreamContext context)
2020-07-20 11:46:01.3982||DEBUG|Ocelot.Errors.Middleware.ExceptionHandlerMiddleware|requestId: 0HM1CCO82S6AR:00000001, previousRequestId: no previous request id, message: ocelot pipeline finished

Ocelot : 13.5.2
Net Core: 2.2

Any help is appreciated..

@lufeiyuan83
Copy link

hi chaitanyaphanikumar
please update your Ocelot Configuration.json
{
"DownstreamPathTemplate": "/api/v1/identity/register",
"DownstreamScheme": "https",
"UseServiceDiscovery": true,
"ServiceName": "IdentityService",
"UpstreamPathTemplate": "/v1/identity/register",
"UpstreamHttpMethod": [ "POST" ],
"LoadBalancerOptions": {
"Type": "LeastConnection"
}
}
],
"GlobalConfiguration": {
"RequestIdKey": "OcRequestId",
"BaseUrl": "https://localhost:44311",
"ServiceDiscoveryProvider": {
"Scheme": "http",
"Host": "localhost",
"Port": 8500,
//////////////////////////////
"Type": "PollConsul"
//////////////////////////////
}
}

@raman-m raman-m added bug Identified as a potential bug medium effort Likely a few days of development effort small effort Likely less than a day of development effort. waiting Waiting for answer to question or feedback from issue raiser labels May 13, 2023
@raman-m
Copy link
Member

raman-m commented May 13, 2023

@chaitanyaphanikumar Hi Chaitanya Phani Kumar!

Could you confirm, please, that @lufeiyuan83 advice helped to resolve the issue by changing provider type?

@raman-m raman-m added accepted Bug or feature would be accepted as a PR or is being worked on and removed waiting Waiting for answer to question or feedback from issue raiser labels Sep 7, 2023
@raman-m
Copy link
Member

raman-m commented Sep 7, 2023

The bug has been accepted due to open PR #1562

raman-m added a commit that referenced this issue Sep 29, 2023
…ements and fix errors (#1670)

* fixing some issues in poll consul:
- Timer is not thread safe, avoiding usage of it
- No Ressources are returned for first call
- Using a providers pool, instead of creating a new provider instance

* line endings

* adding some test cases

* Using a lock instead of SemaphoreSlim

* Improve code readability

* CA2211: Non-constant fields should not be visible

* Use IOcelotLogger to remove warnings & messages of static code analysis (aka IDE0052)

* Fix errors with unit tests discovery. Remove legacy life hacks of discovering tests on .NET Core

* Update unit tests

* Also refactoring the kubernetes provider factory (like consul and eureka)

* shorten references...

* const before...

* Some minor fixes, using Equals Ordinal ignore case and a string constant for provider type definition instead of string litterals. Fixing usings.

* waiting a bit longer then?

* @RaynaldM code review

* renaming PollKubernetes to PollKube

* ... odd...

* ... very odd, we have an issue with configuration update duration...

* IDE0002: Name can be simplified

* All tests passing locally, hopefully it works online

* just a bit of cleanup

* Some missing braces and commas

* Update servicediscovery.rst: Review and update "Consul" section

---------

Co-authored-by: Guillaume Gnaegi <[email protected]>
Co-authored-by: raman-m <[email protected]>
@raman-m raman-m added merged Issue has been merged to dev and is waiting for the next release Service Discovery Ocelot feature: Service Discovery and removed medium effort Likely a few days of development effort small effort Likely less than a day of development effort. accepted Bug or feature would be accepted as a PR or is being worked on labels Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identified as a potential bug merged Issue has been merged to dev and is waiting for the next release Service Discovery Ocelot feature: Service Discovery
Projects
None yet
3 participants