Forum Discussion

Karel_Kral's avatar
Karel_Kral
Copper Contributor
Sep 05, 2023

VssUnauthorizedException: VS30063: You are not authorized to access... in web service application

In my service application, I am calling Azure DevOps server using https://learn.microsoft.com/en-us/azure/devops/integrate/concepts/dotnet-client-libraries?view=azure-devops for .Net. This application server processes requests from 30 clients in React and part of this processing is calling Azure DevOps through the client libraries.

The application works fine for weeks or days, but after some time, every call to Azure DevOps ends with an exception. This exception is returned for every call to Azure DevOps service until restarting the application.

Microsoft.VisualStudio.Services.Common.VssUnauthorizedException: VS30063: You are not authorized to access https://dev.azure.com/. at Microsoft.VisualStudio.Services.Common.VssHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.VisualStudio.Services.Common.VssHttpRetryMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.SendAsync(HttpRequestMessage message, HttpCompletionOption completionOption, Object userState, CancellationToken cancellationToken) at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.SendAsync[T](HttpRequestMessage message, Object userState, CancellationToken cancellationToken) ....

So this is not issue with invalid PAT or invalid authorization. I think that this is not the issue with usage limitation but rather hitting some connection count limit. But there is no documented limit and I am not creating multiple connections. This is one application on one computer. I did some performance tests and I am not hitting the limit of TSTU max.

Some details about code:

I am using one singleton connection for the whole application:

        VssBasicCredential credentials = new(string.Empty, _orgInfoProvider.Credentials.PersonalAccessToken);
        Uri serverUri = new Uri(_options.ServerUrl).Combine(orgName);
        VssConnection connection = new VssConnection(serverUri, new VssCredentials(credentials));

then I am creating several clients using this code:

        GitHttpClient client = connection.GetClient<GitHttpClient>();
        var pullRequest = await Client.GetPullRequestByIdAsync(projectName, pullRequestId);

These clients are called from multiple threads (as recommended practice) and are living for the whole app application life.

Before this, application was working fine for years on On-Premises server. Clients and connections had short-lived lifetime, so I created VssConnection for every request, call conn.GetClient<T> and disposed client and connection.

After moving to Azure DevOps services, I was getting exception above after several minutes of working. So I rewrote the application using long-living instances and one connection only and it seems to work for some time. But I have the issue described above.

2 Replies

  • Hi Karel,
    We've had a similar issue, for use what fixed it was to re-create the client on exception.
    We figured out that the client's token/authentication expires after a certain time, so re-creating the client with a new token should be the solution.

    We just wrapped the client with a proxy to re-create it on failures.

    Hope this helps you as well!
    • Karel_Kral's avatar
      Karel_Kral
      Copper Contributor
      Hi Anton, thanks for confirming the issue. I have created a watchdog that checks AzDevOps availability and in the case of problems, restarts the application.
      After watching the watchdog results, I think that the root cause of the issue is on the server side. The application works ok for 3 months, after that, one day two failures happened.
      Your solution is also good, thanks for sharing.

Resources