FormatException: An invalid IP address was specified

2,180 views
Skip to first unread message

Ashenafi

unread,
Aug 16, 2012, 10:49:19 AM8/16/12
to servic...@googlegroups.com
I recently upgrade ServiceStack from version 3.6.9.29748 to 3.9.4.0 and run into the below exception.
I have a few nodes running ServiceStack services behind a loadbalancer.
The exception occurs intermittently.

Has anyone run into this?

Here is the stack trace
[FormatException]: hashcode { 51426437 } 
{ Message : An invalid IP address was specified. StackTrace :
at System.Net.IPAddress.InternalParse(String ipString, Boolean tryParse
at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.GetEndpointAttributes(IHttpRequest request) in EndpointHandlerBase.cs: line 237 
at ServiceStack.WebHost.Endpoints.RestHandler.GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, Object request) in RestHandler.cs: line 88 
at ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName) in RestHandler.cs: line 80
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, ref Boolean completedSynchronously
Source : System TargetSite : System.Net.IPAddress InternalParse(System.String, Boolean) HelpLink : {NULL} Data : {} InnerException : {NULL} } 

Demis Bellot

unread,
Aug 16, 2012, 10:54:08 AM8/16/12
to servic...@googlegroups.com
What's the IP Address causing this issue?

Ashenafi

unread,
Aug 16, 2012, 2:44:32 PM8/16/12
to servic...@googlegroups.com
Here is sample of the request header when the error happened

RequestType = GET  
ContentLength = 0  
ContentEncoding = System.Text.UTF8Encoding  
ContentType = application/json  
UserAgent = Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0  
IsAuthenticated = False  
IsSecureConnection = True  
UserHostAddress = 204.2.145.235  
UserHostName = 204.2.145.235 

Demis Bellot

unread,
Aug 16, 2012, 3:05:42 PM8/16/12
to servic...@googlegroups.com
Yeah that's not it as this test passes: 
https://github.com/ServiceStack/ServiceStack/commit/87a51116957ebf12c5e51be443a3776c25894463 

I need to find someway to repro it. Like the real ip used, or the full HTTP Request header that shows the exception.

Froyke

unread,
Aug 20, 2012, 11:28:25 AM8/20/12
to servic...@googlegroups.com
This is probably related to non valid IP address provided in the x-forwarded-for header by the LB.
I have found a weird proxy that sent me "10.212.0.0,127.0.0.1" as the value. That have caused this fail.
I have opened an issue which is partially related https://github.com/ServiceStack/ServiceStack/issues/226
But probably in your case there is a real need to fetch the 'real' ip. This Logic probably needs to be improved in SS.

Ashenafi

unread,
Aug 24, 2012, 2:21:52 PM8/24/12
to servic...@googlegroups.com
"X-Forwarded-For" header seems the cause of the issue for a failing request behind a LB/Http proxy.

Thanks,

Demis Bellot

unread,
Aug 24, 2012, 2:26:48 PM8/24/12
to servic...@googlegroups.com
Note, if you can supply failing tests we can fix it and ensure that future changes don't break it again :)

Daniel Butler

unread,
Aug 28, 2012, 10:37:39 AM8/28/12
to servic...@googlegroups.com
I have added some unit tests which fail with these addresses as part of this pull request:

https://github.com/ServiceStack/ServiceStack/pull/235

Demis Bellot

unread,
Aug 29, 2012, 12:07:57 PM8/29/12
to servic...@googlegroups.com
should be fixed now.
Reply all
Reply to author
Forward
0 new messages