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

ArgumentOutOfRangeException #673

Closed
ogomaemmanuel opened this issue Oct 27, 2018 · 4 comments
Closed

ArgumentOutOfRangeException #673

ogomaemmanuel opened this issue Oct 27, 2018 · 4 comments
Labels
needs validation Issue has not been replicated or verified yet question Initially seen a question could become a new feature or bug or closed ;)

Comments

@ogomaemmanuel
Copy link

Expected Behavior / New Feature

Actual Behavior / Motivation for New Feature

oceloterror
I keep getting argumentoutofrange exception in the newer version of Ocelot while using asp net core 2.1. Ealier version of the eg 5.3.0 with asp net core 2.0 have no problems, I need to use the websocket feature added on version greater than 9

Program.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;

namespace ShoppingCartApiGateWay
{
public class Program
{
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
.AddJsonFile("ocelot.json")
.AddEnvironmentVariables();
})
.ConfigureServices(s => {
s.AddOcelot();
})
.ConfigureLogging((hostingContext, logging) =>
{
//add your logging
})
// .UseIISIntegration()
.Configure(app =>
{
app.UseOcelot().Wait();
})
.Build()
.Run();
}
}
}

Ocelot.json

{
"ReRoutes": [
//Basket reroutes config
{
"DownstreamPathTemplate": "/api/Basket",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "basketservice",
"Port": 80
}
],
"UpstreamPathTemplate": "/api/Basket",
"UpstreamHttpMethod": [ "Options", "Delete", "Post", "Get" ]

},
{
  "DownstreamPathTemplate": "/api/Basket/{everything}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "basketservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/Basket/{everything}",
  "UpstreamHttpMethod": [ "Options", "Delete", "Get" ]

},


{
  "DownstreamPathTemplate": "/api/Basket/{customerId?}/{itemId}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "basketservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/Basket/{customerId?}/{itemId}",
  "UpstreamHttpMethod": [ "Options", "Put", "Delete" ]
},


//manufacturers  reroutes config
{
  "DownstreamPathTemplate": "/api/Manufacturer",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "manufacturerservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/Manufacturer",
  "UpstreamHttpMethod": [ "Options", "Post", "Get" ]
},
{
  "DownstreamPathTemplate": "/api/Manufacturer/{id}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "manufacturerservice",
      "Port": 9002
    }
  ],
  "UpstreamPathTemplate": "/api/Manufacturer/{id}",
  "UpstreamHttpMethod": [ "Options", "Put", "Get", "Delete" ]
},


// orders reroutes config
{
  "DownstreamPathTemplate": "/api/orders",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "orderservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/orders",
  "UpstreamHttpMethod": [ "Options", "Post", "Get" ]
},

{
  "DownstreamPathTemplate": "/api/orders/{id}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "orderservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/orders/{id}",
  "UpstreamHttpMethod": [ "Options", "Get", "Delete", "Put" ]
},
{
  "DownstreamPathTemplate": "/api/orders/customer/{id}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "orderservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/orders/customer/{id}",
  "UpstreamHttpMethod": [ "Get" ]
},

{
  "DownstreamPathTemplate": "/api/orders/order-items/{id}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "orderservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/orders/order-items/{id}",
  "UpstreamHttpMethod": [ "Options", "Get" ]
},

//payment methods reroute config

{
  "DownstreamPathTemplate": "/api/PaymentMethods",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "paymentmethodservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/PaymentMethods",
  "UpstreamHttpMethod": [ "Options", "Get", "Post" ],
  "Key": "paymentMethods"
},

{
  "DownstreamPathTemplate": "/api/PaymentMethods/{id}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "paymentmethodservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/PaymentMethods/{id}",
  "UpstreamHttpMethod": [ "Options", "Get", "Put", "Delete" ]
  //"AuthenticationOptions": {
  //  "AuthenticationProviderKey": "TestKey",
  //  "AllowedScopes": []
  //}

},

//productcategory services reroutes
{
  "DownstreamPathTemplate": "/api/ProductsCategory",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "productcategoryservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/ProductsCategory",
  "UpstreamHttpMethod": [ "Options", "Get", "Post", "PUt" ]
  //"AuthenticationOptions": {
  //  "AuthenticationProviderKey": "TestKey",
  //  "AllowedScopes": []
  //}
},

{
  "DownstreamPathTemplate": "/api/ProductsCategory/{id}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "productcategoryservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/ProductsCategory/{id}",
  "UpstreamHttpMethod": [ "Options", "Get", "PUt", "Delete" ]

},

//products reroutes settings
{
  "DownstreamPathTemplate": "/api/products/all",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "productservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/products/all",
  "UpstreamHttpMethod": [ "Options", "Get" ]

},
{
  "DownstreamPathTemplate": "/api/products/{id}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "productservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/products/{id}",
  "UpstreamHttpMethod": [ "Options", "Get", "Delete" ]
  //"AuthenticationOptions": {
  //  "AuthenticationProviderKey": "TestKey",
  //  "AllowedScopes": []
  //}
},

{
  "DownstreamPathTemplate": "/api/products",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "productservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/products",
  "UpstreamHttpMethod": [ "Options", "Post" ]
  //"AuthenticationOptions": {
  //  "AuthenticationProviderKey": "TestKey",
  //  "AllowedScopes": []
  //}
},

//shipment methods reroutes config
{
  "DownstreamPathTemplate": "/api/ShipmentMethods",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "shipmentmethodservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/ShipmentMethods",
  "UpstreamHttpMethod": [ "Options", "Get", "Post" ],
  "Key": "shipmentMethods"
},
{
  "DownstreamPathTemplate": "/api/ShipmentMethods/{id}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "shipmentmethodservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/ShipmentMethods/{id}",
  "UpstreamHttpMethod": [ "Options", "Get", "Put", "Delete" ]
  //"AuthenticationOptions": {
  //  "AuthenticationProviderKey": "TestKey",
  //  "AllowedScopes": []
  //}
},

{
  "DownstreamPathTemplate": "/api/MpesaPayment",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "paymentservice",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/MpesaPayment",
  "UpstreamHttpMethod": [ "Options", "Post" ]
},

{
  "DownstreamPathTemplate": "/Signalr/NotificationHub/negotiate",
  "UpstreamPathTemplate": "/Signalr/NotificationHub/negotiate",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "signalrnotificationservice",
      "Port": 80
    }
  ],
  "UpstreamHttpMethod": [ "Options", "Get", "Post" ]
},

{
  "DownstreamPathTemplate": "/Signalr/NotificationHub",
  "UpstreamPathTemplate": "/Signalr/NotificationHub",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "signalrnotificationservice",
      "Port": 80
    }
  ],
  "UpstreamHttpMethod": [ "Options", "Get", "Post" ]
}

],
"Aggregates": [
{
"ReRouteKeys": [
"paymentMethods",
"shipmentMethods"
],
"UpstreamPathTemplate": "/CheckoutOption"
}
],
"GlobalConfiguration": {}
}

@davidni
Copy link
Contributor

davidni commented Nov 29, 2018

@ogomaemmanuel can you copy the full output of your exception.ToString()? The stack trace might help pinpoint where it's coming from.

@philproctor philproctor added the question Initially seen a question could become a new feature or bug or closed ;) label Jan 9, 2019
@philproctor
Copy link
Contributor

Stack trace would be helpful

@philproctor philproctor added the needs validation Issue has not been replicated or verified yet label Jan 10, 2019
@ChrisSwinchatt
Copy link
Contributor

ChrisSwinchatt commented Jan 15, 2019

@davidni @philproctor

I've just gotten the same error. Here's the full exception details:

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)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Foo.ApiGateway.StartingUp.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in /src/Foo.ApiGateway/StartingUp/Startup.cs:line 58
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String shutdownMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
   at Foo.ApiGateway.Program.Main(String[] args) in /src/Foo.ApiGateway/Program.cs:line 20
---> (Inner Exception #0) 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)<---

This was triggered after updating a K8S configmap and restarting the pod (POSTing to the administration API didn't trigger it; in fact it didn't seem to do anything despite returning a 200 response). There doesn't appear to be anything wrong with the config. (I can't post it here because it's 2000 lines long and contains internal stuff.)

Edit: Fixed. In my case it was caused by reusing catch-alls, e.g. "/foo/{everything}/bar/{everything}". This is the same issue as #683 .

@raman-m
Copy link
Member

raman-m commented Jun 15, 2024

Outdated issue ❗

@ogomaemmanuel

You have the right to reopen this issue in the future if you come with a PR ready

@raman-m raman-m closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs validation Issue has not been replicated or verified yet question Initially seen a question could become a new feature or bug or closed ;)
Projects
None yet
Development

No branches or pull requests

5 participants