0

Essentially, while using the .NET version of the Email Migration v2 Google API our application is sending up too many requests per second to a single Google Apps mailbox/user; greater than 1 Request per second. A GoogleApiException is being returned which is fine, and expected, however the body of the error message states a service unavailable (503) error has occurred, but yet the "HttpStatusCode" property of that same GoogleApiException instance is equal to an Http status code of Gone (410), I will include a code snippet and some log output below. At this point, see the questions section at the bottom or read on for better detail.

What steps will reproduce the problem?

Create a process/application that does the following:

  1. Create a Google.Apis.Admin.email_migration_v2.AdminService object, properly initialize it using your OAuth2.0 credentials.
  2. For each message that needs to be sent to Google Apps Create a Google.Apis.Admin.email_migration_v2.MailResource.InsertMediaUpload instance using the AdminService object from above through using AdminService.Mail.Insert() providing proper parameters.
  3. Call MailResource.InsertMediaUpload.UploadAsync while catching any errors that occur.

Do the following:

  1. Begin sending messages at an exponential rate by spooling off hundreds of instances of this process/application all pointing to the same user, using the same OAuth2.0 credentials.
  2. Sit back sip your mountain dew and wait for the [503] errors to roll in...

Once errors start rolling in close down your applications.. no need to hammer the poor Google servers other than for testing the applications exception handling..

What is the expected output? What do you see instead?

Using an instance of the following type: Google.GoogleApiException

One would expect to see the instance's HttpStatusCode property be equivalent to System.Net.HttpStatusCode.ServiceUnavailable instead of System.Net.HttpStatusCode.Gone

What version of the product are you using?

Google.Apis.Admin.Email_Migration_v2 (1.8.1.20)

What is your operating system?

Windows Server 2008 R2 Enterprise (SP1)

What is your IDE?

Visual Studio 2013 Premium

What is the .NET framework version?

4.0.30319

Please provide any additional information below.

Here is a code snippet of the method being called for uploading purposes:

    UploadStatus TryUpload(MailResource.InsertMediaUpload insertMediaUpload)
    {
        try
        {
            IUploadProgress uploadProgress = insertMediaUpload.UploadAsync(_cancellationToken).Result; // Task.Result locks this thread until completed.

            if (uploadProgress != null && uploadProgress.Exception != null)
            {
                // Display additional information on any of the various exceptions that can be returned by the upload call.
                HandleUploadProgressException(uploadProgress);
            }

            return uploadProgress != null ? uploadProgress.Status : UploadStatus.Failed;

Here is a code snippet from the method that is displaying the output of the exception.

    void HandleUploadProgressException(IUploadProgress uploadProgress)
    {
        if (uploadProgress.Exception is GoogleApiException)
        {
            GoogleApiException gApiEx = uploadProgress.Exception as GoogleApiException;
            throw new vsEventException(vsMapEvent.MapHttpError(gApiEx.HttpStatusCode, vsEventMessages.Id.errGmailUnidentifiableGoogleApiException),
                String.Format("GoogleApiException handled in GmailMessenger.HandleUploadProgressException.  HttpStatusCode: {0}", gApiEx.HttpStatusCode),
                gApiEx);
        }

Here is paraphrased output of the GoogleApiException handled by the HandleUploadProgressException method: (note using a custom logging class; outputting to DebugView)

** Context Info **

Error attempting to write item to Gmail...

** Event Details **

VS-EventID: 30003(errGmailTryUpload) GoogleApiException handled in GmailMessenger.HandleUploadProgressException. HttpStatusCode: Gone

** Inner Exception Details **

The service admin has thrown an exception: Google.GoogleApiException: Google.Apis.Requests.RequestError

Service unavailable. Please try again [503]

Errors [ Message[Service unavailable. Please try again] Location[ - ] Reason[backendError] Domain[global] ]

at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)

at Google.Apis.Upload.ResumableUpload`1.d__e.MoveNext()

Questions:

  1. Can anyone shed some light on if this is expected behavior or a bug?
  2. If this is the expected result how should the application handle a 410 based error? I know that when most if not all 400 errors are encountered processing of that particalar item should stop, but this does not seem to be a local issue, more a server side issue.

I appreciate any responses returned, I know it can be hard for questions as specific as this.

580
  • 470
  • 2
  • 12
  • Possible, helpful hint, disclaimer slight tangent... At some rate you should get a bunch of 412 - Limit Reached errors. What we have gathered through using this application is that each Google Apps user/mailbox has a pending items queue that when you send a message it is first put into this queue before being processed by a Google Server and put into the users mailbox. If this queue becomes full and you attempt to send another message you will receive a 412 error. – 580 Mar 11 '15 at 20:22
  • Options are to wait before sending another message, you'll have to wait however long the Google Apps server takes to process the next message in line before sending another. Or start sending to another user because the queue is per user. This took us a little while to figure out so cheers if you're having this issue. Note the pending messages queue appeared to hold about 100-150 items before throwing 412 errors. 503 errors only occur when sending messages into the queue at a higher rate that 1 request per second to one user's mailbox. – 580 Mar 11 '15 at 20:23
  • Not an answer to your question but be aware that the Email Migration API is deprecated and replaced by the Gmail API. Any code you write against Email Migration API v2 now won't have a very long life https://developers.google.com/admin-sdk/email-migration/ – Jay Lee Mar 12 '15 at 16:24
  • Ugh.. I appreciate the comment, hadn't bothered visiting the API's home page in a long time as there was no need to. I work on a good number of applications so I don't always have time to focus on one in particular. Surprisingly my colleagues were also unaware, something so simple overlooked for so long... I should of figured something was up as there was no update to the NuGet package since November of last year... I really do appreciate the point out! Depressing as it was something right under my nose =( – 580 Mar 12 '15 at 20:55

0 Answers0