-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Concurrent requests with different services, using consul, returns the same service and then 404 #2119
Comments
Hello @minnocenti901! What is your full name?
The "GlobalConfiguration": {
"BaseUrl": "http://localhost:5280", // this is crucial!
"RequestIdKey": "ApiGateway",
"ServiceDiscoveryProvider": {
"Type": "Consul",
"Port": "8502",
"Host": "192.168.0.204"
}
} Please could you provide the complete |
🆗 Could you show us complete Consul configuration please, service mappings, nodes etc.? Regarding networking... I see you use learning solution at local machine in Docker or without, right? |
🆗 Please revert the version to 23.2.2 and conduct the same tests. |
Adding BaseUrl didn't solve the issue.
I'm running it inside visual studio 2022 professional on windows 11. The issue is also present if running it in a docker container on Ubuntu Server 22.04 I forgot to mention that I have upgraded from Ocelot 22.0.1 on .NET6 to latest version 23.3.3 on .NET8. Before the upgrade everything was working perfectly. Consul is running on docker compose with this .yml:
|
Reverting to 23.2.2 fixed the issue |
Hello! It's Massimiliano Innocenti |
It seems we may have encountered a bug following a significant refactoring of the Consul provider by PR #2067 and commit 34cb3eb
@minnocenti901 Excellent! Continue using version 23.2.2 until we have resolved or understood the problem. @ggnaegi, could you please join us and collaborate on this issue? Have you deployed version 23.3.x to Production? |
@raman-m Thank you for your time! |
LoL Massimiliano Innocenti on LinkedIn |
I prefer not to answer :) |
@minnocenti901, are you a C# developer? |
Yes
No, thank you. I don't have time :\ Im sorry |
How did you detect the issue? Are you using Ocelot for certain projects? |
I use it as main api gateway for a microservices architecture. I need to upgrade from NET6 to NET8 due to upcoming end of service and with the update I had to recheck that everything still works. Then comes the issue |
Understood. For the time being, please proceed with version 23.2.2 for your solution upgrade. |
@minnocenti901 commented Jul 10, 2024, 1:08 PM:
Good. Did you change anything in the Consul services registrations, or was there nothing except a version increase? It seems the issue was introduced by PR #2067. You are correct; the issue might be related to concurrency. Max, could you please share the JSON from the Consul client? I need the complete list of services registered in Consul. |
I just increase version of Ocelot. How do I get the JSON you need? |
@raman-m @minnocenti901 I'm on it, cheers |
Let me to proceed with this, @ggnaegi. Please concentrate on issue #2116. It appears that the author is not intending to contribute but rather aims to direct our attention to this bug. |
…rviceBuilder` with `ConsulProviderFactory` refactoring to make it thread safe and friendly (#2151) * Review tests * History of Service Discovery testing: add traits * LoadBalancer traits * #2119 Steps to Reproduce * Reuse service handlers of `ConcurrentSteps` * Reuse service counters of `ConcurrentSteps` * Add LoadBalancer namespace and move classes * Move `Lease` * Move `LeaseEventArgs` * Analyze load balancers aka `ILoadBalancerAnalyzer` interface objects * Prefer using named local methods as delegates over anonymous methods for awesome call stack, ensuring the delegate's typed result matches the typed balancer's creator. Additionally, employ an IServiceProvider workaround. * Review load balancing. Assert service & leasing counters as concurrent step. Final version of acceptance test. * Fixed naming violation for asynchronous methods: `Lease` -> `LeaseAsync` * Fix ugly reflection issue of dymanic detection in favor of static type property * Propagate the `ConsulRegistryConfiguration` object through `HttpContext` in the scoped version of the default service builder, utilizing the injected `IHttpContextAccessor` object. Update `ConsulProviderFactory`. Update docs. Update tests. * Add tests from clean experiment * Final review of the tests * Review `IHttpContextAccessor` logic. Convert anonymous delegates to named ones in placeholders processing * Tried to enhance more, but failed
@minnocenti901 Max, are you online? |
…Blue Olympic Balumbes release * #2084 Apply default config file paths in `GetMergedOcelotJson` when providing the `folder` argument of `AddOcelot` (#2120) * Adding unit test first * Fixing default global config file not being found in folder * Adding PR trait to test * Backing out whitespace changes * Code review by @raman-m * Create Configuration feature folder and move test classes * Adjust namespace and review what we have * Acceptance tests for #2084 user scenario --------- Co-authored-by: Raman Maksimchuk <[email protected]> * Bump Steeltoe.Discovery.Eureka from 3.2.5 to 3.2.8 in /src/Ocelot.Provider.Eureka (#2122) * Bump Steeltoe.Discovery.Eureka in /src/Ocelot.Provider.Eureka Bumps [Steeltoe.Discovery.Eureka](https://github.com/SteeltoeOSS/Steeltoe) from 3.2.5 to 3.2.8. - [Release notes](https://github.com/SteeltoeOSS/Steeltoe/releases) - [Changelog](https://github.com/SteeltoeOSS/Steeltoe/blob/main/Steeltoe.Release.ruleset) - [Commits](SteeltoeOSS/Steeltoe@3.2.5...3.2.8) --- updated-dependencies: - dependency-name: Steeltoe.Discovery.Eureka dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> * Bump Steeltoe.Discovery.ClientCore from 3.2.5 to 3.2.8 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Raman Maksimchuk <[email protected]> * #2110 Review load balancing and independent fetching the list of services in `Kube` provider (#2111) * Move the creation of the services list from the class field to the method, to prevent modification list from different threads * Early return after data checking * Add unit test for concurrent get list of services * Add logging for invalid service configuration error in RoundRobin load balancer * Code review by @raman-m * Workaround for mistakes made during acceptance testing of load balancing versus service discovery, where tests designed for parallel requests were mistakenly executed sequentially. This resulted in load balancers being loaded by sequential `HttpClient` calls, which was a significant oversight. * Let's DRY StickySessionsTests * Add acceptance tests, but... RoundRobin is not actually RoundRobin 😁 -> 😆 * Independent static indexing iterators per route via service names * Stabilize `CookieStickySessions` load balancer. Review tests after refactoring of `RoundRobin` load balancer * Refactor Lease operation for load balancing. Review LeastConnection load balancer * Leasing mechanism in Round Robin load balancer * Acceptance tests, final version * Apply Retry pattern for K8s endpoint integration * Fix IDE warnings and messages * Follow suggestions and fix issues from code review by @ggnaegi * Bump KubeClient from 2.4.10 to 2.5.8 * Fix warnings * Final version of `Retry` pattern --------- Co-authored-by: Raman Maksimchuk <[email protected]> * Downgrade the Warning to Information on missing `Content-Length` header in `MultiplexingMiddleware` (#2146) * fix: downgrade the warning to information on missing content-length header * chore: add route name to logs * test: fixing multiplexing middleware tests * Code review by @raman-m --------- Co-authored-by: Paul Roy <[email protected]> Co-authored-by: Raman Maksimchuk <[email protected]> * Correct the broken link to the GraphQL sample's `README.md` (#2149) Signed-off-by: Emmanuel Ferdman <[email protected]> Co-authored-by: Raman Maksimchuk <[email protected]> * #2116 Escaping unsafe pattern values of `Regex` constructor derived from URL query parameter values containing special `Regex` chars (#2150) * regex escape handling for url templates * refactored regex method to lamda version * Quick code review by @raman-m * added acceptance test for url regex bug * moved acceptance test to routing tests * Convert to theory: define 2 test cases --------- Co-authored-by: Raman Maksimchuk <[email protected]> * #2119 Review load balancing (2nd round) and redesign `DefaultConsulServiceBuilder` with `ConsulProviderFactory` refactoring to make it thread safe and friendly (#2151) * Review tests * History of Service Discovery testing: add traits * LoadBalancer traits * #2119 Steps to Reproduce * Reuse service handlers of `ConcurrentSteps` * Reuse service counters of `ConcurrentSteps` * Add LoadBalancer namespace and move classes * Move `Lease` * Move `LeaseEventArgs` * Analyze load balancers aka `ILoadBalancerAnalyzer` interface objects * Prefer using named local methods as delegates over anonymous methods for awesome call stack, ensuring the delegate's typed result matches the typed balancer's creator. Additionally, employ an IServiceProvider workaround. * Review load balancing. Assert service & leasing counters as concurrent step. Final version of acceptance test. * Fixed naming violation for asynchronous methods: `Lease` -> `LeaseAsync` * Fix ugly reflection issue of dymanic detection in favor of static type property * Propagate the `ConsulRegistryConfiguration` object through `HttpContext` in the scoped version of the default service builder, utilizing the injected `IHttpContextAccessor` object. Update `ConsulProviderFactory`. Update docs. Update tests. * Add tests from clean experiment * Final review of the tests * Review `IHttpContextAccessor` logic. Convert anonymous delegates to named ones in placeholders processing * Tried to enhance more, but failed --------- Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Emmanuel Ferdman <[email protected]> Co-authored-by: Ben Bartholomew <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Roman <[email protected]> Co-authored-by: Paul Roy <[email protected]> Co-authored-by: Paul Roy <[email protected]> Co-authored-by: Emmanuel Ferdman <[email protected]> Co-authored-by: Finn <[email protected]>
Yes, i've seen you marked as closed. You need some testing? |
The hotfix has been released in ver. 23.3.4, so you can download the pack from NuGet. |
Local and Staging, cannot run tests on production |
Can you handle deployment? What is your role in the project, QA? |
Yes I can. I have to update to 23.3.4? |
Emm... Yes, please, update version, deploy and test. |
Updated from 23.2.2 to 23.3.4.
Configuration is not changed and it is the same as the one is posted EDIT: |
Did you read this: |
Default service builder uses node name as a host! Ocelot/src/Ocelot.Provider.Consul/DefaultConsulServiceBuilder.cs Lines 96 to 97 in 6088515
This is current best practice because node may/should contain the same hosts but different ports in load balancing scenarios, when Docker containers are deployed with different ports but same host. In this case it is logical thing to assign real host name to node name. But I guess if Consul has setup by default, seems node names are abstract. It's curious how your environment functioned properly with version 23.2.2, given that the "node name as host name" feature has been available since version 13.5.2. |
After the implementation of a "MyConsulServiceBuilder" using only the service.address it works perfectly. Thanks.
I don't know :( it worked. |
I'm just curious, could you make node name empty in Consul admin? Seems not, right? I've asked AI and got this answer :D
|
Great! Congrats! 🥳 |
Local and Staging works perfectly. Every concurrent request receives the correct route. Can't test in production, sorry |
It appears we've officially resolved the issue. 😃
No worries! Are other team members responsible for Production? Thank you for your contribution! |
Expected Behavior
Ocelot should request from Consul the correct service for every route
Actual Behavior
If concurrent requests, ocelot uses the same servicename for every concurrent request
Steps to Reproduce the Problem
On consul I have 2 services registered:
ProjectsService with url
http://localhost:5013
CustomersService with url
http://localhost:5004
Ocelot is running on
http://localhost:5280
Global configuration:
Routes configuration:
Then, at startup, I make 3 different requests at the same time:
http://localhost:5280/projects/api/projects
http://localhost:5280/projects/api/industrialSectors
http://localhost:5280/customers/api/customers
This is the log in console with LogLevel Debug
I'm expecting that for the route /customers it uses CustomersService instead of ProjectsService.
Specifications
The text was updated successfully, but these errors were encountered: