question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting "A task was cancelled" error in Android Publisher v3

See original GitHub issue

Hello,

I’m facing a inconsistente problem. I have a CI to upload build on Google Play automatically, but on the last month I received the error “A task was cancelled” only a few times when I run the upload process.

But this problem is becoming more frequent, yesterday and today I’m always receiving this error message when try to run the upload proccess.

I tested this problem on isolated console application and received the same error.

Could you help me?

This is the code for run upload process. The BundleSettings, AndroidPublisherService and AppEdit don’t have any problem, the problem only occurs when I use the Upload method.

        BundleSettings configs = BundleSettings.FromFilePath(configFilePath);
         
        if (configs == null)
        {
            throw new Exception("Cannot load a valid BundleConfig");
        }
        
        //Create publisherService
        var androidPublisherService = CreateGoogleConsoleAPIService(configs);

        // Create a new edit to make changes to your listing.
        var edit = CreateAnEditObject(androidPublisherService, configs);
        
        UploadAabFile(configs, androidPublisherService, edit).Upload() ;

Used Methods

    private static EditsResource.BundlesResource.UploadMediaUpload UploadAabFile(BundleSettings configs,
        AndroidPublisherService androidPublisherService,
        AppEdit edit)
    {
        Console.WriteLine("Upload started for aab: " + Path.GetFileName(configs.ApkPath));
        var upload = androidPublisherService.Edits.Bundles.Upload(
            configs.PackageName,
            edit.Id,
            new FileStream(configs.ApkPath, FileMode.Open),
            "application/octet-stream"
        );
        return upload;
    }

    private static AppEdit CreateAnEditObject(AndroidPublisherService androidPublisherService,
        BundleSettings configs)
    {
        var edit = androidPublisherService.Edits
            .Insert(null /** no content */, configs.PackageName)
            .Execute();
        Console.WriteLine("Created edit with id: " +
                          edit.Id +
                          " (valid for " + edit.ExpiryTimeSeconds + " seconds)");
        return edit;
    }

    private static AndroidPublisherService CreateGoogleConsoleAPIService(BundleSettings configs)
    {
        var cred = GoogleCredential.FromJson(File.ReadAllText(configs.JsonKeyPath));
        cred = cred.CreateScoped(new[] {AndroidPublisherService.Scope.Androidpublisher});

        // Create the AndroidPublisherService.
        var androidPublisherService = new AndroidPublisherService(new BaseClientService.Initializer
            {HttpClientInitializer = cred});
        return androidPublisherService;
    }

This is the result error

Unhandled exception. System.AggregateException: One or more errors occurred. (A task was canceled.) —> System.Threading.Tasks.TaskCanceledException: A task was canceled. — End of inner exception stack trace — at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result() at Google.Apis.Upload.ResumableUpload.Upload() at ConsoleGPlayAPITool.Program.Main(String[] args) in E:\DoubleDashStudios\Projetos\GooglePlayAPIConsoleUploader\ConsoleGPlayAPITool\Program.cs:line 35

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jskeetcommented, Aug 25, 2022

I’m so glad! If that hadn’t been it, I’d have been a bit clueless as to what to do next!

0reactions
leopthurlercommented, Aug 25, 2022

Hello @jskeet,

I think that you are correct, I change the code to set 10 minutes of timeout and the problem apparently was solved. Thank you. 😃

Here has the code if someone needs.

    private static AndroidPublisherService CreateGoogleConsoleAPIService(BundleSettings configs)
    {
        var cred = GoogleCredential.FromJson(File.ReadAllText(configs.JsonKeyPath));
        cred = cred.CreateScoped(new[] {AndroidPublisherService.Scope.Androidpublisher});

        // Create the AndroidPublisherService.
        var androidPublisherService = new AndroidPublisherService(new BaseClientService.Initializer
            {HttpClientInitializer = cred});
        
        androidPublisherService.HttpClient.Timeout = TimeSpan.FromMinutes(10);
        return androidPublisherService;
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

A task was canceled · Issue #1394 · googleapis/google-api ...
Hi. When executing .Execute() method found in the ClientServiceRequest class. (public TResponse Execute();) it fails with an unhelpful ...
Read more >
HttpClient - task was cancelled - How to get the exact error ...
I have the following test code. I always get the "Task was cancelled" error after looping 316934 or 361992 times. If I am...
Read more >
"A Task was cancelled" exception in Blazor Server : r/csharp
Task being cancelled simply means your task timed out. Your db call is probably failing but not returning a failure, like if you...
Read more >
"Task Was Cancelled" when building - Developer Community
The Error List shows no errors. Only the output window showed "Task was cancelled". 3. If it happens again, I will grab the...
Read more >
Known issues with Android Studio and Android Gradle Plugin
A problem occurred configuring project ':myapp'. Could not get unknown property 'manifestOutputFile' for task ':myapp:processDebugManifest' of type com.android.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found