1
votes

I have recently started using the Gmail API as opposed to IMAP. I am using the .Net client library for calling the API.

On a random basis I am recieving the Error

"An error occurred while sending the request" when executing a Get Request of a Message

                    UsersResource.MessagesResource.GetRequest gr = gs.Users.Messages.Get(emailAccount, msgId);
                    if (isRaw)
                    {
                        gr.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw;
                        Message m = gr.Execute();

My observations are that this is a random error that occurs now and then. I can run 10 Requests and then there will be a fail. I am running the same request on the same infrastructure each time.

I have also noted that the performance is not very consistent - it can sometimes take 10 seconds and other times sub-second.

Is anybody else experiencing issues such as this?

Thanks for your help,

UPDATE

I am calling the same message and it is a small one with no attachments. I have a load tester that requests it 100 times. The errors are to do with the closing of an underlying connection. I am going to try a different web host to see if that is a factor. Here are the full error messages:

Error on Message Get

|System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult) at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)

Error during authentication

|System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult) at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) --- End of inner exception stack trace --- at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) at Google.Apis.Auth.OAuth2.ServiceAccountCredential.d__b.MoveNext()

Paul C

1
I've done some further testing and this is only happening from my Azure hosted site. When run from Amazon AWS or localhost there is no issue. I'm guessing it is a communication issue between Azure & Google - not a gmail api issue. - PNC
maybe you exceeded the quotas? check this out: developers.google.com/apps-script/guides/services/… - Tal

1 Answers

1
votes

This is an issue with Azure hosting.

I have confirmed that if I use an Azure Web site or even a virtual machine that there are 5-10% error rates for calling Google APIs.

The same issue occurs whether authenticating, calling Gmail API or calendar API.

No response from MSFT so I'm going to host elsewhere.

Hope this saves somebody with the same issue.