2011-02-08 37 views
1

我們有一個應用程序使用HttpWebRequest通過HTTPS(由apache前端處理)將數據發佈到遠程服務器。HTTPS上的HttpWebRequest的隨機問題

大多數時候,一切正常。

不時,我們有以下異常:

WebException occured SecureChannelFailure ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. 
    at System.Net.HttpWebRequest.GetRequestStream() 

但這種異常被捕獲,該應用程序試了一下後,一切再次變細(東西必須在HTTPS握手失敗,我不知道是什麼)。

最近,我們有一個新的問題,我們無法重現:

在Web站點側(阿帕奇),我們有一個HTTP 403,具有消息「重新談判握手失敗:由客戶端不接受!?「。

在.NET客戶端,我們有一個無聲的崩潰(或應用程序卡住沒有超時,我不知道)。我們唯一知道的是:它不是由應用程序正確處理的WebException。 不幸的是,這部分代碼沒有足夠的異常日誌記錄,我們無法輕鬆地使用System.Net跟蹤部署新版本的應用程序,以便進行握手調查。

有沒有人有什麼可能是這個問題的想法?

下面是代碼:

 HttpWebRequest req = WebRequest.Create(new Uri(url)) as HttpWebRequest; 

     // set client certificate and server certificate validation callback 
     ConfigureWebRequestSecurity(req); 

     req.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip"); 
     req.AutomaticDecompression = DecompressionMethods.GZip; 
     req.Method = "POST"; 
     req.ContentType = "text/xml"; 
     req.ContentLength = data.Length; 

     HttpWebResponse resp = null; 
     try 
     { 
      using (Stream post = req.GetRequestStream()) 
      { 
       post.Write(data, 0, data.Length); 
      } 

      resp = req.GetResponse() as HttpWebResponse; 

      Log.Logger.DebugFormat("REST : HTTP Response={0}({1})", (int)resp.StatusCode, resp.StatusCode.ToString()); 

      if (!resp.StatusCode.Equals(HttpStatusCode.OK)) 
      { 
       throw new MOServerErrorException("The server did not respond with status 200 (OK), but with " + resp.StatusCode); 
      } 
     } 
     catch (WebException e) 
     { 
      string m = string.Format("REST : WebException occured {0}", e.Status.ToString()); 
      throw new MOServerErrorException(m, e); 
     } 
     finally 
     { 
      if (resp != null) 
       resp.Close(); 
     } 

編輯: 好吧,我已經成功地重現該問題。線程在GetRequestStream()中掛起。 這裏是堆棧:

mscorlib.dll!System.Threading.WaitHandle.WaitOne(long timeout, bool exitContext) + 0x2f bytes 
    mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext) + 0x25 bytes  
> System.dll!System.Net.LazyAsyncResult.WaitForCompletion(bool snap) + 0xd3 bytes 
    System.dll!System.Net.Security.SslState.CheckEnqueueRead(byte[] buffer = {byte[4096]}, int offset = 0, int count = 4096, System.Net.AsyncProtocolRequest request) + 0x194 bytes 
    System.dll!System.Net.Security._SslStream.StartReading(byte[] buffer = {byte[4096]}, int offset = 0, int count = 4096, System.Net.AsyncProtocolRequest asyncRequest = null) + 0x6d bytes  
    System.dll!System.Net.Security._SslStream.ProcessRead(byte[] buffer, int offset, int count, System.Net.AsyncProtocolRequest asyncRequest = null) + 0x6b bytes 
    System.dll!System.Net.TlsStream.Read(byte[] buffer, int offset, int size) + 0x58 bytes 
    System.dll!System.Net.PooledStream.Read(byte[] buffer, int offset, int size) + 0x1b bytes 
    System.dll!System.Net.Connection.SyncRead(System.Net.HttpWebRequest request = {System.Net.HttpWebRequest}, bool userRetrievedStream = false, bool probeRead = true) + 0x12a bytes 
    System.dll!System.Net.Connection.PollAndRead(System.Net.HttpWebRequest request, bool userRetrievedStream) + 0x5a bytes 
    System.dll!System.Net.ConnectStream.PollAndRead(bool userRetrievedStream) + 0x1b bytes 
    System.dll!System.Net.HttpWebRequest.EndWriteHeaders(bool async) + 0xa2 bytes 
    System.dll!System.Net.HttpWebRequest.WriteHeadersCallback(System.Net.WebExceptionStatus errorStatus, System.Net.ConnectStream stream = {System.Net.ConnectStream}, bool async) + 0x16 bytes 
    System.dll!System.Net.ConnectStream.WriteHeaders(bool async) + 0x2d1 bytes 
    System.dll!System.Net.HttpWebRequest.EndSubmitRequest() + 0x82 bytes  
    System.dll!System.Net.HttpWebRequest.SetRequestSubmitDone(System.Net.ConnectStream submitStream) + 0xf7 bytes 
    System.dll!System.Net.Connection.CompleteConnection(bool async, System.Net.HttpWebRequest request = {System.Net.HttpWebRequest}) + 0x158 bytes 
    System.dll!System.Net.Connection.CompleteStartConnection(bool async, System.Net.HttpWebRequest httpWebRequest) + 0x177 bytes  
    System.dll!System.Net.Connection.CompleteStartRequest(bool onSubmitThread, System.Net.HttpWebRequest request = {System.Net.HttpWebRequest}, System.Net.TriState needReConnect = True) + 0x9a bytes 
    System.dll!System.Net.Connection.SubmitRequest(System.Net.HttpWebRequest request = {System.Net.HttpWebRequest}) + 0x293 bytes 
    System.dll!System.Net.ServicePoint.SubmitRequest(System.Net.HttpWebRequest request = {System.Net.HttpWebRequest}, string connName = "S>1054081937") + 0x7c bytes  
    System.dll!System.Net.HttpWebRequest.SubmitRequest(System.Net.ServicePoint servicePoint) + 0xf9 bytes 
    System.dll!System.Net.HttpWebRequest.GetRequestStream(out System.Net.TransportContext context = null) + 0x1d3 bytes 
    System.dll!System.Net.HttpWebRequest.GetRequestStream() + 0xe bytes 

它掛在這裏,沒有超時。聽起來像網絡堆棧中的錯誤!

+0

附加信息:在應用程序中有一個特殊情況,該代碼由後臺線程執行,後臺線程具有「最後一次機會」異常處理程序和日誌記錄,並且沒有異常記錄!我們最好的選擇是,請求被卡住了,沒有超時,但我不知道這可能會如何。也許是網絡堆棧的東西? – mathieu 2011-02-08 18:47:19

回答

0

看來是KB980817

我沒安裝修補程序提出(設置推移罰款...但System.dll中保持不變)。 作爲解決方法,我使用API​​的異步版本(Begin ... End)並自行管理超時。