2017-10-04 3 views
1

nous avons un webapi, Azure SQL DB et keyvault hébergé sur azure. Tout allait bien jusqu'à environ une semaine en arrière. Nous avons dû supprimer et recréer le groupe de ressources. Après cela, nous avons commencé à obtenir sporadique 500 "erreur interne du serveur" le débogage plus loin, nous avons constaté que KeyVaultClient GetSecretAsync jette l'erreur ci-dessous:Erreur Sporadic 500 lors de l'appel GetSecretAsync à partir de webAPI

04/10/2017 15: 08: 06: 265 - [7664: 40] - ERREUR - MyService.Helper.ConnectionFactory -

Une ou plusieurs erreurs se sont produites. à System.Threading.Tasks.Task`1.GetResultCore (Boolean waitCompletionNotification) à Common.KeyVaultReader.KeyVaultHelper.GetSecret (String secretName) à syngo.DataCloud.CD.Service.Helper.ConnectionFactory..ctor (IKeyVaultHelper keyVaultHelper)

Mais ce qui déroute, c'est que le même code fonctionne si nous déployons sur un autre point de terminaison. Même dans le même déploiement, il fonctionne pour un ensemble d'appels GET/POST mais échoue pour un autre.

Je n'arrive pas à savoir comment le réparer.

Code KeyvaultHelper GetSecret ci-dessous:

using (var kvClient = new KeyVaultClient(GetToken)) 
{ 
    var secret = Task.Run(async() => 
    { 
    return await kvClient.GetSecretAsync(secretURI, secretName).ConfigureAwait(false); 
    }); 
    return secret.Result.Value; 
} 

Mise à jour:

Aggregate exception as below: 

2017-10-04 15:18:47:233 - [7664:86] - ERROR - MyHelper.ExceptionHandling.GlobalExceptionLogger - WebAPI exception : System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 104.42.136.180:443 
    at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) 
    at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) 
    --- End of inner exception stack trace --- 
    at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 
    at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) 
    --- End of inner exception stack trace --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Rest.RetryDelegatingHandler.<>c__DisplayClass11_0.<<SendAsync>b__1>d.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Rest.RetryDelegatingHandler.<SendAsync>d__11.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Azure.KeyVault.KeyVaultClient.<GetSecretWithHttpMessagesAsync>d__61.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Azure.KeyVault.KeyVaultClientExtensions.<GetSecretAsync>d__11.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Common.KeyVaultReader.KeyVaultHelper.<>c__DisplayClass7_0.<<GetSecret>b__0>d.MoveNext() 
    --- End of inner exception stack trace --- 
    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) 
    at Common.KeyVaultReader.KeyVaultHelper.GetSecret(String secretName) 
    at Common.Authentication.Entitlement.EntitleAttribute.CheckFeatureSupported(String strToken, List`1 features) 
    at System.Web.Http.AuthorizeAttribute.OnAuthorization(HttpActionContext actionContext) 
    at System.Web.Http.Filters.AuthorizationFilterAttribute.OnAuthorizationAsync(HttpActionContext actionContext, CancellationToken cancellationToken) 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext() 
---> (Inner Exception #0) System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 104.42.136.180:443 
    at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) 
    at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) 
    --- End of inner exception stack trace --- 
    at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 
    at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) 
    --- End of inner exception stack trace --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Rest.RetryDelegatingHandler.<>c__DisplayClass11_0.<<SendAsync>b__1>d.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Rest.RetryDelegatingHandler.<SendAsync>d__11.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Azure.KeyVault.KeyVaultClient.<GetSecretWithHttpMessagesAsync>d__61.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Azure.KeyVault.KeyVaultClientExtensions.<GetSecretAsync>d__11.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Common.KeyVaultReader.KeyVaultHelper.<>c__DisplayClass7_0.<<GetSecret>b__0>d.MoveNext()<--- 
+0

Il serait utile si vous installez une meilleure connexion autour de cela. Il lance probablement une 'AggregateException'. Celui-là contient l'exception réelle qui l'a causé. Si vous mettez un try autour de ça, qui capture l'exception AggregateException, vous pouvez enregistrer les exceptions internes à partir de cela. – juunas

+0

@juunas J'ai ajouté les logs d'exception. Merci de l'avoir signalé. – ashwin

Répondre

0

Nous ne pouvions pas comprendre quel était le problème. Mais depuis que l'accès keyvault fonctionne initialement et échoue seulement après environ 40/50 appels nous avons décidé de mettre en cache le secret en utilisant system.runtime.caching.memorycache

Cela semble résoudre le problème.

Mais la question sur la limite d'accès keyvault se pose. Keyvault a-t-il des limites à l'accès simultané aux secrets?