簡體   English   中英

對ServiceStack的PUT / POST請求掛起

[英]PUT/POST requests to ServiceStack hanging

當我向ServiceStack服務發出POST和PUT請求(此刻正在使用HTTP偵聽器獨立運行)時,有時會發現請求可以正常工作,有時我的客戶端(HTTPie)將掛起。 一段時間后,我會在Visual Studio的“輸出”窗口中看到一些信息:

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

這種確切的嘗試會花費一些時間,而會使另一些失敗。 我正在使用帶有.NET4和VS 2010的來自NuGet的最新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"
}

}

看來是AVG Anti-Virus業務的元凶。 我知道我討厭殺毒軟件是有原因的!

我發現該代碼在另一台機器上運行良好,這告訴我這是我的開發箱設置所特有的。 我嘗試將計算機恢復到最低限度,刪除未使用的軟件,VS擴展,插件等。我嘗試了IIS Express和ServiceStack的自托管模式。 我嘗試將代碼移出Dropbox。 沒有任何區別。

當我最終禁用AVG時,問題消失了,幾個小時后,它仍然運行正常。

要進行調試,最好下載項目源代碼並調試框架源代碼本身。 我建議嘗試在集成測試中復制此行為,以便我們找出造成此問題的原因。 有關如何執行此操作的示例,請參見ServiceStack的http偵聽器集成測試

要在ServiceStack中啟用日志記錄,您只需要在啟動/初始化AppHost之前將日志工廠設置為您選擇提供者即可。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM