2

I get this exception intermitently when trying to post some data over HTTPS. Running on mono 2.10.1 (now changed to 2.10.9). I have no clue as to why this is happening, it doesn't seem to be related to request size (about 2.5MB), as other requests of similar size are working.

// these arguments are not null, as I can see them in a log.
var response1 = web1.UploadData(address, "POST", buffer);

Stack trace mono 2.10.1:

System.Net.WebException: An error occurred performing a WebClient request. ---> System.IO.IOException: IO exception during Write. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at Mono.Security.Protocol.Tls.SslStreamBase.InternalBeginWrite (Mono.Security.Protocol.Tls.InternalAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslStreamBase.InternalBeginWrite (Mono.Security.Protocol.Tls.InternalAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  at Mono.Security.Protocol.Tls.SslStreamBase.BeginWrite (System.Byte[] buffer, Int32 offset, Int32 count, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0 
  at System.Net.WebConnection.BeginWrite (System.Net.HttpWebRequest request, System.Byte[] buffer, Int32 offset, Int32 size, System.AsyncCallback cb, System.Object state) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Net.WebClient.UploadData (System.Uri address, System.String method, System.Byte[] data) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Net.WebClient:UploadData (System.Uri,string,byte[])

With mono 2.10.9 I get a different error:

System.Net.WebException: Error getting response stream (ReadDone1): ReceiveFailure ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
  at Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert (AlertLevel alertLevel, AlertDescription alertDesc) [0x00000] in <filename unknown>:0
  at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
  at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x00000] in <filename unknown>:0
  at System.Net.WebClient.ReadAll (System.Net.WebRequest request, System.Object userToken) [0x00000] in <filename unknown>:0
  at System.Net.WebClient.UploadDataCore (System.Uri address, System.String method, System.Byte[] data, System.Object userToken) [0x00000] in <filename unknown>:0
  at System.Net.WebClient.UploadData (System.Uri address, System.String method, System.Byte[] data) [0x00000] in <filename unknown>:0
Benbob
  • 13,876
  • 18
  • 79
  • 114
  • Tried with mono 2.10.9 and the error message is now different, see the stack trace above. – Benbob May 02 '13 at 22:36
  • Mono 3.x is an order of magnitude better than 2.x, please try 3, not 2 – knocte May 03 '13 at 00:40
  • As this is an HTTPS related issue, I suggest you try to capture network packets so as to see whether the TLS/SSL handshake packets can tell what is the culprit. Before that you might run `mozroots --import --sync` to update your local certificates and then try again. – Lex Li May 03 '13 at 06:06

2 Answers2

1

It seems to be an intermittent network issue which the network layer should handle. The issue goes away with subsequent attempts.

Certificates had no effect. The only way I found around this was to catch the exception and retry the request, creating a new WebClient object (as some Headers are cleared).

I've basically put the code in a loop which attempts to upload the data several times.

int maxAttempts = 5;
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
    try {
        if (attempt > 1) {
             // Wait a few seconds
             Thread.Sleep(new TimeSpan(0, 0, 10));
             Logger.Output(string.Format("Retrying request, try: {0}", attempt));
        }
        using (var webClient = new WebClient()) {
            webClient.Headers.Add("Content-Type", string.Format("multipart/form-data; boundary={0}", boundary));
            Logger.Output(webClient.Headers.ToString());
            var response1 = webClient.UploadData(address, "POST", buffer);
        }
        Logger.Output("Table {0} added successfully", table);
        break;
    } catch (WebException e) {
        // More logging here
        if (attempt == maxAttempts) {
            throw; // Re-throw it, clearly something is wrong if it fails x times.
        }
    }
}
Benbob
  • 13,876
  • 18
  • 79
  • 114
0

The The authentication or decryption has failed. maybe a bug of mono, use curl should work. see this post.

Community
  • 1
  • 1
IlPADlI
  • 1,943
  • 18
  • 22