2012-09-26 105 views
2

当我向我的ServiceStack服务(此时与HTTP侦听器独立运行)发出POST和PUT请求时,有时会发现请求会起作用,有时我的客户端(HTTPie)会挂起。过了一会儿,我会看到一些信息在Visual Studio Output窗口: -对ServiceStack挂起的PUT/POST请求

A first chance exception of type 'System.Net.HttpListenerException' occurred in System.dll 
A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in ServiceStack.dll 
A first chance exception of type 'System.Net.HttpListenerException' occurred in System.dll 
A first chance exception of type 'System.Net.HttpListenerException' occurred in ServiceStack.dll 
A first chance exception of type 'System.Net.HttpListenerException' occurred in ServiceStack.dll 
A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in ServiceStack.dll 
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll 

我设法使内置的ServiceStack日志记录,并提供了更多的细节: -

ERROR: Error occured while Processing Request: Could not deserialize 'application/json; charset=utf-8' 
    request using WebServices.Dto.Country' 
Error: System.Net.HttpListenerException (0x80004005): The I/O operation has been aborted because of either 
    a thread exit or an application request 
    at System.Net.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
    at System.IO.StreamReader.ReadBuffer() 
    at System.IO.StreamReader.ReadToEnd() 
    at ServiceStack.Text.JsonSerializer.DeserializeFromStream(Type type, Stream stream) in C:\src\ServiceStack.Text\ 
    src\ServiceStack.Text\JsonSerializer.cs:line 164 
    at ServiceStack.ServiceModel.Serialization.JsonDataContractDeserializer.DeserializeFromStream(Type type, Stream 
    stream) in C:\src\ServiceStack\src\ServiceStack.Common\ServiceModel\Serialization\JsonDataContractDeserializer.cs:line 86 
    at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.CreateContentTypeRequest(IHttpRequest httpReq, 
    Type requestType, String contentType) in C:\src\ServiceStack\src\ServiceStack\WebHost.Endpoints\Support\ 
    EndpointHandlerBase.cs:line 100, 
Exception: Could not deserialize 'application/json; charset=utf-8' request using WebServices.Dto.Country' 
Error: System.Net.HttpListenerException (0x80004005): The I/O operation has been aborted because of either a thread 
    exit or an application request 
    at System.Net.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
    at System.IO.StreamReader.ReadBuffer() 
    at System.IO.StreamReader.ReadToEnd() 
    at ServiceStack.Text.JsonSerializer.DeserializeFromStream(Type type, Stream stream) in C:\src\ServiceStack.Text\src\ 
    ServiceStack.Text\JsonSerializer.cs:line 164 
    at ServiceStack.ServiceModel.Serialization.JsonDataContractDeserializer.DeserializeFromStream(Type type, Stream 
    stream) in C:\src\ServiceStack\src\ServiceStack.Common\ServiceModel\Serialization\JsonDataContractDeserializer.cs:line 86 
    at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.CreateContentTypeRequest(IHttpRequest httpReq, 
    Type requestType, String contentType) in C:\src\ServiceStack\src\ServiceStack\WebHost.Endpoints\Support\EndpointHandlerBase.cs:line 100 
ERROR: Could not WriteTextToResponse: An operation was attempted on a nonexistent network connection, Exception: 
    An operation was attempted on a nonexistent network connection 
ERROR: Could not WriteTextToResponse: An operation was attempted on a nonexistent network connection, Exception: 
    An operation was attempted on a nonexistent network connection 
INFO: Failed to write error to response: {0}, Exception: An operation was attempted on a nonexistent network connection 

我想提出我的测试要求是这样的: -

http --json post "http://localhost:1337/countries/" DefaultHouse_Id=2 Name=Denmark 

这个确切的尝试工作一段时间,失败等。 我使用NuGet与.NET4和VS 2010的最新ServiceStack。 看起来,该请求根本没有达到我自己的代码。

有谁知道什么可能导致这种情况,或者我可以如何调试它?

编辑:如果不知道它的相关或不相关,但有时我也得到这样的: -

{ 

"ResponseStatus":{ 

"ErrorCode":"TypeLoadException", 
"Message":"Could not load type 'ServiceStack.ServiceInterface.HttpRequestApplyToExtensions' from assembly 'ServiceStack.ServiceInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.", 
"StackTrace":" at RulesLayer.AuditFilterAttribute.Execute(IHttpRequest req, IHttpResponse res, Object requestDto)\n at  ServiceStack.ServiceInterface.RequestFilterAttribute.RequestFilter(IHttpRequest req, IHttpResponse res, Object requestDto) in C:\\src\\ServiceStack\\src\\ServiceStack.ServiceInterface\\RequestFilterAttribute.cs:line 41\n at ServiceStack.WebHost.Endpoints.EndpointHost.ApplyRequestFilters(IHttpRequest httpReq, IHttpResponse httpRes, Object requestDto) in C:\\src\\ServiceStack\\src\\ServiceStack\\WebHost.Endpoints\\EndpointHost.cs:line 303\n at ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName) in C:\\src\\ServiceStack\\src\\ServiceStack\\WebHost.Endpoints\\RestHandler.cs:line 63" 
} 

} 
+0

@mythz TypeLoadException不相关 - 我追踪到混合DLL版本。一个组件使用不同的ServiceStack DLL。另一个问题仍然存在,所以我正在深入研究。 – JohnCC

回答

3

看来AVG反病毒业务是罪魁祸首。我知道我讨厌反病毒软件的原因!

我发现代码在另一台机器上工作正常,它告诉我这是我的开箱设置特定的东西。我尝试将机器剥离到最低限度,删除未使用的软件,VS扩展,插件等。我尝试了IIS Express和ServiceStack的自托管模式。我试着将我的代码移出Dropbox。没有什么区别。

当我终于禁用AVG时,问题就消失了,几个小时后它仍然完美运行。

1

要调试,没有什么比下载project source code和调试框架源代码本身。我建议尝试在集成测试中复制此行为,以便我们找出造成这种情况的原因。有关如何执行此操作的示例,请参阅ServiceStack的http listener integration tests

要在ServiceStack中启用日志记录,只需在启动/初始化AppHost之前将日志工厂设置为provider of your choice即可。

LogManager.LogFactory = new ConsoleLogFactory(typeof(Program)); 
+0

似乎发生的事情是,它进入公共静态对象JsonSerializer.DeserializeFromStream(Type type,Stream stream),并且当它调用上下文的输入流中的reader.ReadToEnd()时,它会阻塞,直到网络级别的某个东西最终放弃,此时会生成异常串,因为反序列化失败并且连接现在已关闭。我尝试在行this.ProcessRequest(context)中打破HttpListenerBase.ListenerCallback(IAsyncResult asyncResult)。我做了context.Request.InputStream.ReadFully()。立即转储(),它也阻止然后失败 – JohnCC

+0

因此,似乎HttpListener没有创建一个有效的输入流对象,但我还不确定为什么。 – JohnCC

+0

不确定它是否有用,但这里是从运行失败的跟踪http://paste.ubuntu.com/1230797/ – JohnCC