-
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
Not Found (404) Error with Service Discovery - Docker / Consul #1329
Comments
I have exactly the same problem. It's obvious that Ocelot does not resolve service routes properly with Consul when deployed to Docker. |
Have you tried to repeat the request? I also receive the 404 status code the first time when I use PollConsul type, but subsequent requests are handled well. And it is not dependent on the use of containers. |
I also have this issue, have you figured out how to fix it? |
Nope :(
V sob., 7. nov. 2020 08:45 je oseba LeeStevens318 <[email protected]>
napisala:
… Have you tried to repeat the request? I also receive the 404 status code
the first time when I use PollConsul type, but subsequent requests are
handled well. And it is not dependent on the use of containers.
I also have this issue, have you figured out how to fix it?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1329 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJJUVCYOP5HQ67XRHZQENCLSOT3I7ANCNFSM4QRLQSCA>
.
|
Hi @jlukawska , I found exactly what you suggest time ago. After clone the project and inspect what it does in the moment to request the collection of registered services in the first async call to the Consul API the result is null, but subsequent requests return a valid collection. |
@johha86 , if I remember well the problem is that the first polling starts when application starts. And application starts with the first request and that's why there is no services information yet. |
I have the same problem ...first call on every route get me a 404 ... second call is fine.... |
Hi, I had found the reason of the problem and how to fixe it. When you configure Ocelot to use Service Discovery as PollConsul mode, an IServiceDiscoveryProvider is created with a timer in the Constructor. In the callback of the timer, happens the Poll of the available services in Consul into a collection. But the initialization of this timer happens at the first time you call Ocelot. So, the first time you call ocelot, such collection is empty and you receive a Not Found 404. The repository with this code is Archived so I can't do a PR with the Fix. What I did was do a Fork of the repository ,add the fix and use my forked project instead the Nuget Package.
Other option is implement an IHostedService that perform calls to an endpoint at the beginning of the execution of the application. I will keep this issue open because the original code doesn't have a solution yet. Maybe I could maintain the original repository. |
hmmmm i see your point... But im not sure... your update is running on the first startup... then it collects the services and hold them... but i have the 404 on every routes first call... not only initial |
Yes, I know. The forked repo with solution is here. This contain the source code of Ocelot.Provider.Consul and I commited my changes into the branch issues-1329-not-found-error-with-consul. |
@3dotsDev I'm experiencing the same issue. I'm currently reading the code and I'm trying to implement a suitable solution for me there. We have the ConsulProviderFactory, it's a singleton. So I thought that carefully maintaining a list with the discovery providers (one discovery provider per service) would do the trick. In the Polling class, I'm retrieving the clients the first time the Get method is called. The timer is also started there (using a semaphore slim to avoid race conditions). I'm not sure it's a good solution (neverending debate about locks, concurrent dictionaries or semaphore slim). |
I'm wondering if this could be a solution... The idea is the following: "Avoiding polling" (using time intervals), retrieving the services until they are available on every request. As soon as the services are available, waiting until "polling interval" reached. public async Task<List<Service>> Get()
{
await _semaphore.WaitAsync();
try
{
var refreshTime = _lastUpdateTime.AddMilliseconds(_pollingInterval);
//checking elapsed time + if any service available
if (refreshTime >= DateTime.UtcNow && _services.Any())
{
return _services;
}
_logger.LogInformation($"Retrieving new client information for service: {ServiceName}");
_services = await _consulServiceDiscoveryProvider.Get();
_lastUpdateTime = DateTime.UtcNow;
return _services;
}
finally
{
_semaphore.Release();
}
} |
Hello @ggnaegi If you want to "Avoid polling" I think that you only need to setup Ocelot following the instruction: |
@johha86 sure, but then it's for every request and I thought it would help if we wouldn't keep retrieving the services on every request. In my case, I can see quite a performance improvement. It's a bit chatty otherwise, you call _consulServiceDiscoveryProvider.Get which then call consul to get the consul clients information on every request. So I don't want to avoid polling per se, I'm just looking for a solution that is not too chatty... It's an hybrid implementation then: To summarize:
|
@johha86 @matjazbravc @LeeStevens318 @3dotsDev Could you review the code and/or verify the solution please? |
…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]>
Expected Behavior
Reroute to the downstream path.
Actual Behavior
Any request return a Not Found Error(404) with the following message in the VS output window:
Steps to Reproduce the Problem
I created two ASP Net Core Web API projects. The first one implement a API Gateway using Ocelot with Consul and the second one is a simple Web API Service with a endpoint routed to /api/v1/File. Both project are initialized by a docker composer project
Specifications
The service looks registered in the web client.
If I ping beetwen the consul container, the private gateway and the service container they can be reached each other.
How can I solve this problem?
The text was updated successfully, but these errors were encountered: