2012-09-26 107 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