Azure / azure-service-bus

☁️ Azure Service Bus service issue tracking and samples
https://azure.microsoft.com/services/service-bus
MIT License
586 stars 776 forks source link

Azure.Identity.AuthenticationFailedException: Response was not set, make sure SendAsync was called #652

Closed fp-jcorriveau closed 1 year ago

fp-jcorriveau commented 1 year ago

I'm trying to work with Azure Service Bus from an old project and I'm facing an issue. It seems impossible to connect as I always get this error:

Azure.Identity.AuthenticationFailedException: ClientSecretCredential authentication failed: Response was not set, make sure SendAsync was called

Here is a code snippet of what I'm trying to do

var adminClient = new ServiceBusAdministrationClient(
    mySettings.AzureServiceBus.Endpoint,
    new ClientSecretCredential(mySettings.AzureServiceBus.TenantId,
        mySettings.AzureServiceBus.ClientId, mySettings.AzureServiceBus.ClientSecret));

var exists = await adminClient.SubscriptionExistsAsync(myTopic, mySubName).ConfigureAwait(false); 

And the diagnostics:

[Informational] Azure-Identity: ClientSecretCredential.GetToken invoked. Scopes: [ https://servicebus.azure.net/.default ] ParentRequestId: 8cd8075d-fb77-4479-bf12-d612fff0de99 [Informational] Azure-Identity: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [02/01/2023 23:46:30 - ] MSAL MSAL.Desktop with assembly version '4.30.1.0'. CorrelationId(e1994990-3e32-43b9-83e5-55a325de668a) [Informational] Azure-Identity: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [02/01/2023 23:46:30 - ] === AcquireTokenForClientParameters === SendX5C: False ForceRefresh: False

[Informational] Azure-Identity: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [02/01/2023 23:46:30 - ] === Request Data === Authority Provided? - True Scopes - https://servicebus.azure.net/.default Extra Query Params Keys (space separated) - ApiId - AcquireTokenForClient IsConfidentialClient - True SendX5C - False LoginHint ? False IsBrokerConfigured - False HomeAccountId - False CorrelationId - e1994990-3e32-43b9-83e5-55a325de668a

[Informational] Azure-Identity: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [02/01/2023 23:46:30 - ] === Token Acquisition (ClientCredentialRequest) started:

    Authority Host: login.microsoftonline.com

[Informational] Azure-Identity: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [02/01/2023 23:46:30 - ] Azure region was not configured or could not be discovered. Not using a regional authority. [Informational] Azure-Identity: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [02/01/2023 23:46:30 - ] Azure region was not configured or could not be discovered. Not using a regional authority. [Informational] Azure-Identity: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [02/01/2023 23:46:30 - ] Fetching instance discovery from the network from host login.microsoftonline.com. [Informational] Azure-Core: Request [76254b44-7f17-42bc-9810-ae56aab73c66] GET https://login.microsoftonline.com/common/discovery/instance?api-version=REDACTED&authorization_endpoint=REDACTED x-client-SKU:REDACTED x-client-Ver:REDACTED x-client-CPU:REDACTED x-client-OS:REDACTED client-request-id:REDACTED return-client-request-id:REDACTED x-app-name:REDACTED x-app-ver:REDACTED x-ms-client-request-id:REDACTED x-ms-return-client-request-id:REDACTED User-Agent:REDACTED client assembly: Azure.Identity [Informational] Azure-Core: Request [76254b44-7f17-42bc-9810-ae56aab73c66] exception System.InvalidOperationException: Response was not set, make sure SendAsync was called à Azure.Core.HttpMessage.get_Response() à System.Diagnostics.DiagnosticSourceEventSource.TransformSpec.PropertySpec.PropertyFetch.RefTypedFetchProperty2.Fetch(Object obj) à System.Diagnostics.DiagnosticSourceEventSource.TransformSpec.PropertySpec.Fetch(Object obj) à System.Diagnostics.DiagnosticSourceEventSource.TransformSpec.Morph(Object obj) à System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform.Morph(Object args) à System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform.<>c__DisplayClass2_1.<.ctor>b__2(KeyValuePair2 evnt) à System.Diagnostics.DiagnosticSourceEventSource.CallbackObserver`1.OnNext(T value) à System.Diagnostics.DiagnosticListener.Write(String name, Object value) à Azure.Core.Pipeline.DiagnosticScope.ActivityAdapter.Dispose() à Azure.Core.Pipeline.DiagnosticScope.Dispose() à Azure.Core.Pipeline.RequestActivityPolicy.d11.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter.GetResult() à Azure.Core.Pipeline.ResponseBodyPolicy.d5.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter.GetResult() à Azure.Core.Pipeline.LoggingPolicy.d__9.MoveNext() [Error] Azure-Identity: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [02/01/2023 23:46:30 - ] Exception type: System.InvalidOperationException

à Azure.Core.HttpMessage.get_Response() à System.Diagnostics.DiagnosticSourceEventSource.TransformSpec.PropertySpec.PropertyFetch.RefTypedFetchProperty2.Fetch(Object obj) à System.Diagnostics.DiagnosticSourceEventSource.TransformSpec.PropertySpec.Fetch(Object obj) à System.Diagnostics.DiagnosticSourceEventSource.TransformSpec.Morph(Object obj) à System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform.Morph(Object args) à System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform.<>c__DisplayClass2_1.<.ctor>b__2(KeyValuePair2 evnt) à System.Diagnostics.DiagnosticSourceEventSource.CallbackObserver1.OnNext(T value) à System.Diagnostics.DiagnosticListener.Write(String name, Object value) à Azure.Core.Pipeline.DiagnosticScope.ActivityAdapter.Dispose() à Azure.Core.Pipeline.DiagnosticScope.Dispose() à Azure.Core.Pipeline.RequestActivityPolicy.<ProcessAsync>d__11.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter.GetResult() à Azure.Core.Pipeline.ResponseBodyPolicy.<ProcessAsync>d__5.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter.GetResult() à Azure.Core.Pipeline.LoggingPolicy.<ProcessAsync>d__9.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter.GetResult() à Azure.Core.Pipeline.RedirectPolicy.<ProcessAsync>d__5.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter.GetResult() à Azure.Core.Pipeline.RetryPolicy.<ProcessAsync>d__11.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() à Azure.Core.Pipeline.RetryPolicy.<ProcessAsync>d__11.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter.GetResult() à Azure.Core.Pipeline.HttpPipeline.<SendRequestAsync>d__11.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Threading.Tasks.ValueTask1.get_Result() à System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1.ConfiguredValueTaskAwaiter.GetResult() à Azure.Core.HttpPipelineMessageHandler.<SendAsync>d__2.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() à System.Net.Http.HttpClient.d58.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Http.HttpManager.d10.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Http.HttpManager.<ExecuteWithRetryAsync>d__8.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Http.HttpManager.d5.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.OAuth2.OAuth2Client.d111.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.OAuth2.OAuth2Client.d9.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Instance.Discovery.NetworkMetadataProvider.d7.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Instance.Discovery.NetworkMetadataProvider.<FetchAllDiscoveryMetadataAsync>d__6.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Instance.Discovery.NetworkMetadataProvider.d4.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Instance.Discovery.InstanceDiscoveryManager.d10.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Instance.Discovery.InstanceDiscoveryManager.<GetMetadataEntryAsync>d__9.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Instance.AuthorityManager.d9.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Internal.Requests.ClientCredentialRequest.d3.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Internal.Requests.ClientCredentialRequest.<ExecuteAsync>d__2.MoveNext() --- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée --- à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) à System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() à Microsoft.Identity.Client.Internal.Requests.RequestBase.d__13.MoveNext() [Informational] Azure-Identity: ClientSecretCredential.GetToken was unable to retrieve an access token. Scopes: [ https://servicebus.azure.net/.default ] ParentRequestId: 8cd8075d-fb77-4479-bf12-d612fff0de99 Exception: Azure.Iden tity.AuthenticationFailedException (0x80131500): ClientSecretCredential authentication failed: Response was not set, make sure SendAsync was called ---> System.InvalidOperationException (0x80131509): Response was not set, make sure SendAsync was called

fp-jcorriveau commented 1 year ago

Day to day I'm using Jetbrains Rider. It fails everytime. Strangely I managed to make it work in debug navigating through the client properties in the debugger. I can't find what, but sometimes it works.

I asked a collegue of mine to try it, he's using Visual Studio and it never fail. So I installed VStudio Community to give it a try, and... it works... Cannot explain the difference.

EldertGrootenboer commented 1 year ago

Closing this issue as it seems unrelated to our service. We would recommend contacting the Jetbrains team so they can investigate if they are doing anything specific that may be causing this issue.

daveaglick commented 1 year ago

Closing this issue as it seems unrelated to our service

We're also using Rider, and also recently seeing this problem. That said, just because Rider is doing something that activates the issue, doesn't mean the issue is actually with them. It could just be that there's a poor design or bug and Rider happens to be the most obvious tool triggering it, but others could as well if they exercised the code in certain ways. That seems like it's still an issue with the originating project IMO, not that caller.

In this case though, I suspect there may be something going on upstream in the Azure SDK HttpMessage class - see the discussion at https://github.com/Azure/azure-sdk-for-net/issues/33294. Specifically, it looks like the Azure ADK HttpMessage throws whenever a DiagnosticSource inspects its properties before a message is sent, which it also looks like the SDK initiates (see the LoggingPolicy call in the stack trace here):

image

bmacombe commented 1 year ago

It's possible something JetBrains is doing is triggering it. I was getting this today and I do use ReSharper in VS 2022. I disabled ReSharper and the exception stopped being thrown while debugging.