2011-02-08 12 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ハンドシェイクに失敗しなければなりません再び罰金になり、I何を知らないか)。ウェブサイト側で

(アパッチ)、私たちは "メッセージで、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(); 
     } 

EDIT: [OK]を、私は問題を再現するために管理してきました。ここ

コードがあります。スレッドは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

+1

私は 'Close()'を呼び出すと応答が遅くなるのを見ました。なぜそれが起こるのかわからないし、頻繁に起こることはありません。私は 'request.Abort()'の後ろに 'response.Close()'があると、* never *が起こることを発見しました。これは、svchost.exeのNetworkインスタンスによるメモリ使用量が高いことに関連している可能性があります。問題は、私を悩ましていて、何の情報も見つけられなかったことです。 –

+0

System.netトレースを有効にできないのはなぜですか?設定が有効になっているアプリケーション設定ファイルを追加するだけです。それがなければ、デバッグするのは難しいでしょう。または、windbg.exeを添付することもできます。アプリがクラッシュすると停止します。その後、管理されたアプリとしてデバッグすることができます。 – feroze

答えて

0

は(セットアップがうまく行く...しかし、System.dllのは変わらない)私が提案した修正プログラムをインストールするために管理していませんでしたKB980817

ているように見えます。 回避策として、私はAPIの非同期バージョン(Begin ... End)を使用しており、自分でタイムアウトを管理しています。