580
580

Reputation: 480

Google.Apis.Admin.Email_Migration_v2 HTTP 410 status code returned for a 503 error

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.

Upvotes: 0

Views: 226

Answers (0)

Related Questions