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 crashes if there are same-named Catch-Alls e.g. foo/{bar}/{bar} #683

Closed
ChrisSwinchatt opened this issue Nov 12, 2018 · 15 comments · Fixed by #1927
Closed

Ocelot crashes if there are same-named Catch-Alls e.g. foo/{bar}/{bar} #683

ChrisSwinchatt opened this issue Nov 12, 2018 · 15 comments · Fixed by #1927
Assignees
Labels
bug Identified as a potential bug Feb'24 February 2024 release merged Issue has been merged to dev and is waiting for the next release proposal Proposal for a new functionality in Ocelot
Milestone

Comments

@ChrisSwinchatt
Copy link
Contributor

Expected Behavior

An informative exception which tells you you can't reuse catch-all names within a path.

Actual Behavior

This exception, which doesn't tell you what is wrong and looks like a bug in Ocelot:

[15:05:22 FTL] Application startup exception
System.AggregateException: One or more errors occurred. (Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: startIndex) ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: startIndex
   at System.String.IndexOf(String value, Int32 startIndex, Int32 count, StringComparison comparisonType)
   at Ocelot.Configuration.Creator.UpstreamTemplatePatternCreator.Create(IReRoute reRoute)
   at Ocelot.Configuration.Creator.ReRoutesCreator.SetUpDownstreamReRoute(FileReRoute fileReRoute, FileGlobalConfiguration globalConfiguration)
   at Ocelot.Configuration.Creator.ReRoutesCreator.<>c__DisplayClass15_0.<Create>b__0(FileReRoute reRoute)
   at System.Linq.Enumerable.SelectListIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Ocelot.Configuration.Creator.FileInternalConfigurationCreator.Create(FileConfiguration fileConfiguration)
   at Ocelot.Middleware.OcelotMiddlewareExtensions.CreateConfiguration(IApplicationBuilder builder)
   at Ocelot.Middleware.OcelotMiddlewareExtensions.UseOcelot(IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration)
   at Ocelot.Middleware.OcelotMiddlewareExtensions.UseOcelot(IApplicationBuilder builder)

Steps to Reproduce the Problem

  1. Create an ocelot.json which contains the following re-route:
        {
            "DownstreamPathTemplate": "/bar/{everything}/{everything}",
            "DownstreamScheme": "http",
            "DownstreamHostAndPorts": [
                {
                    "Host": "foo",
                    "Port": 80
                }
            ],
            "UpstreamPathTemplate": "/foo/bar/{everything}/{everything}",
            "UpstreamHttpMethod": [
                "Get"
            ],
            "Priority": 0
        }
  1. Tell Ocelot to load it
  2. Get the above exception

Specifications

  • Version: 12.0.1
  • Platform: ASP.Net Core 2.1
  • Subsystem:
@ChrisSwinchatt ChrisSwinchatt changed the title Bug: Ocelot crashes if there are consecutive same-named catch-alls (e.g. foo/{bar}/{bar}) Bug: Ocelot crashes if there are same-named catch-alls (e.g. foo/{bar}/{bar}) Nov 13, 2018
@briansantura briansantura added the bug Identified as a potential bug label Jan 5, 2019
@philproctor philproctor added the help wanted Not actively being worked on. If you plan to contribute, please drop a note. label Jan 10, 2019
@philproctor
Copy link
Contributor

Should probably be fixed in the initial reroute validators.

jlukawska added a commit to jlukawska/Ocelot that referenced this issue Dec 16, 2019
TomPallister added a commit that referenced this issue Jan 19, 2020
…t crash on dispose and validate duplicate placeholders in UpstreamPathTemplate

* initial commit for new feature #1077

allow to limit the number of concurrent tcp connection to a downstream service

* protect code against value not in accurate range

add unit test

* Do not crash host on Dispose

* Add test

* Pin GitVersion.CommandLine package version

* #683 validate if there are duplicated placeholders in UpstreamPathTemplate

* Use registered scheme from Eureka (#1087)

* extra test

* very brief mention MaxConnectionsPerServer in docs

* build develop like a PR

* more docs

Co-authored-by: jlukawska <[email protected]>
Co-authored-by: buretjph <[email protected]>
Co-authored-by: Jonathan Mezach <[email protected]>
Co-authored-by: 彭伟 <[email protected]>
TomPallister added a commit that referenced this issue Jan 19, 2020
…namic behaviour

* Make rate-limiting client whitelist dynamic
* Refactor `RateLimitOptions.ClientWhiteList`
* Fix typo in variable `enbleRateLimiting`
* Fix case in variable `clientIdheader`
author Taiwo Otubamowo <[email protected]>

* fix 1045

* #492 log 500 with error log level, acceptance test, unit test

* #492 minor changes

* initial commit for new feature #1077

allow to limit the number of concurrent tcp connection to a downstream service

* protect code against value not in accurate range

add unit test

* Do not crash host on Dispose

* Add test

* Pin GitVersion.CommandLine package version

* #683 validate if there are duplicated placeholders in UpstreamPathTemplate

* Use registered scheme from Eureka (#1087)

* extra test

* very brief mention MaxConnectionsPerServer in docs

* build develop like a PR

* more docs

* test

Co-authored-by: Taiwo O. <[email protected]>
Co-authored-by: Catcher Wong <[email protected]>
Co-authored-by: jlukawska <[email protected]>
Co-authored-by: buretjph <[email protected]>
Co-authored-by: Jonathan Mezach <[email protected]>
Co-authored-by: 彭伟 <[email protected]>
@raman-m
Copy link
Member

raman-m commented Jan 12, 2024

@AlyHKafoury Your next coding challenge? 😉
It is related to CatchAll and Placeholders.

@raman-m raman-m changed the title Bug: Ocelot crashes if there are same-named catch-alls (e.g. foo/{bar}/{bar}) Ocelot crashes if there are same-named Catch-Alls e.g. foo/{bar}/{bar} Jan 12, 2024
@raman-m raman-m added the small effort Likely less than a day of development effort. label Jan 12, 2024
@AlyHKafoury
Copy link
Contributor

@raman-m please assign to me

@raman-m raman-m removed the help wanted Not actively being worked on. If you plan to contribute, please drop a note. label Jan 15, 2024
@raman-m
Copy link
Member

raman-m commented Jan 15, 2024

@AlyHKafoury You're assigned!

@AlyHKafoury
Copy link
Contributor

@raman-m I working on the unit tests

@raman-m
Copy link
Member

raman-m commented Jan 16, 2024

@AlyHKafoury
Because you're working on very similar from #748 & #1911 then you need to create feature branch from AlyHKafoury:Fix-748, otherwise you'll get duplicates.
So, the right thing is branching from AlyHKafoury:Fix-748

@AlyHKafoury
Copy link
Contributor

@raman-m I will rebase to develop now and continue on this

@raman-m
Copy link
Member

raman-m commented Jan 19, 2024

@AlyHKafoury wrote

Yes, Rebase feature branch onto develop please and continue working... Thanks!

@raman-m raman-m added the proposal Proposal for a new functionality in Ocelot label Jan 19, 2024
@raman-m
Copy link
Member

raman-m commented Jan 19, 2024

@ChrisSwinchatt commented on Nov 12, 2018

Hello, Mr. Swinchatt!
Thanks for reporting this funny bug! 😄 How did you test Ocelot in this user scenario, and realize to define this invalid duplicated placeholders? You have a talent for QA! 😉

Yeah, the previous dev team and Tom missed it, and in my opinion, the valid template definition should have all placeholders with different names, and each upstream placeholder should be presented in downstream template too.
Otherwise, route validator should

  • generate Critical error, and Ocelot will not start
  • ignore this route, write Error event to the log and start Ocelot without this route in router mappings.

Make sense? Which design suits your usage scenarios best?
Do you use Ocelot in your current projects?

@AlyHKafoury FYI And let's start discussing...

@raman-m raman-m added the in progress Someone is working on the issue. Could be someone on the team or off. label Jan 19, 2024
@ChrisSwinchatt
Copy link
Contributor Author

Hello @raman-m,

I'm no longer working with Ocelot but IIRC I was writing code to generate an Ocelot config by traversing Swagger documents and it had a bug that resulted in outputting duplicate placeholders. So you could say that my bug found your bug. To your question, I would probably go the route of crashing early, but I leave it to you.

Thanks.

@raman-m
Copy link
Member

raman-m commented Jan 20, 2024

@ChrisSwinchatt Thanks for your reply!

I was writing code to generate an Ocelot config by traversing Swagger documents and...

Since you are a big fan of Swagger, here is some useful information for you 👉

Do not you mind, if we will create separate discussion where we can start brainstorming an integration and Swagger support, and I will invite you also to the thread?


To your question, I would probably go the route of crashing early, but I leave it to you.

🆗 Today I realized that ignoring the route will not be good. To crash early we can generate early validation Critical error, and moreover, if a request comes and matched the route then additionally write Error event to the log for each request. Crashing entire app won't be good, by exception throwing having it as unhandled one. So, we can generate exception, but we have to catch it in Error Mapper and write events into the log.

@AlyHKafoury FYI.
Take into account this new design & requirements, please! ☝️

@AlyHKafoury
Copy link
Contributor

@raman-m Continuing on it

@AlyHKafoury
Copy link
Contributor

@raman-m So, we are gonna throw a Critical error in validation, and then start the application normally then throw an error when a route matching this route is called ? and we will not crash the application ?

@raman-m
Copy link
Member

raman-m commented Jan 25, 2024

@AlyHKafoury ,
I thought you're on vacation. :) Welcome back! 😉

Regarding validation...
You need a small research of validation logic.
Something related to uniqueness of placeholders. If no validator, try to find another validators of uniqueness of route properties. And seems we need to do the same.
Also, figure out, is it possible to write into the log by validation logic. I hope, it is possible outside of validation function.
As far as I know, if validation function returns false then Ocelot crashes and the app won't start at all.
What I'm trying to say, that there is restriction here by validation design. Possibly we have to crash app early, because validation function will return false. In this case we have a record in the log anyway by already implemented design.

The 2nd requirement to write extra record makes sense only if Ocelot won't crash.
Probably, we can skip the 2nd requirement.

@raman-m raman-m removed the small effort Likely less than a day of development effort. label Mar 24, 2024
@raman-m raman-m added Feb'24 February 2024 release and removed in progress Someone is working on the issue. Could be someone on the team or off. labels Mar 24, 2024
@raman-m raman-m added this to the February'24 milestone Mar 24, 2024
raman-m pushed a commit that referenced this issue Mar 26, 2024
* add validation for downstream path also

* add similiar route placeholders

* Add unit tests

* Refactor unit tests

* IDE1006: Naming rule violation

* IDE0028: Collection Initialization can be simplified

* Merge into one theory

* Less `IEnumerable<T>` usage to have less `IEnumerator<T>` objects in favor of the collection one

* Refactor validation of duplicated placeholders

* Finish unit testing

* Publish hidden Service Fabric feature

* Update acceptance tests

* Update integration tests

* Update release notes

---------
The author: Aly Kafoury <@AlyHKafoury>
Co-authored-by: Raman Maksimchuk <[email protected]>
@raman-m raman-m added the merged Issue has been merged to dev and is waiting for the next release label Mar 26, 2024
@raman-m
Copy link
Member

raman-m commented Mar 26, 2024

@ChrisSwinchatt commented on Jan 20

Hi Chris!

FYI: Bug fixed today!

But we used not "an informative exception" solution and chose another solution based on Ocelot configuration validator adding more validation rules for route templates. With this bug fix Ocelot won't start because of validation errors in the log. And user must correct invalid routes with bad templates.

This patch will be released soon...

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 Feb'24 February 2024 release merged Issue has been merged to dev and is waiting for the next release proposal Proposal for a new functionality in Ocelot
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants