Azure / azure-signalr

Azure SignalR Service SDK for .NET
https://aka.ms/signalr-service
MIT License
425 stars 100 forks source link

Unable to add a user to a group in a Linux docker container dotnet-isolated process .NET 6.0 and Functions V4 #1566

Open Arash-Sabet opened 2 years ago

Arash-Sabet commented 2 years ago

Describe the bug

The code fails to add a user to a signalR group in a docker container despite the negotiation passes successfully.

The function's code is per the snippet below:

[Function("AddToGroup")]
public SignalROutputEntity AddUserToGroup(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addtogroup/{groupName}/{myId}")]
    HttpRequestData req,
    string groupName,
    string myId)
{
    var output = new SignalROutputEntity();
    output.Notifications.Add(new
    {
        userId = myId,
        groupName = groupName,
        action = "add"
    });
    output.Response = req.CreateResponse(HttpStatusCode.OK);
    return output;
}

public class SignalROutputEntity
{
    [SignalROutput(HubName = "myHub", ConnectionStringSetting = "AzureSignalRConnectionString")]
    public List<object> Notifications { get; set; } = new();

    public HttpResponseData? Response { get; set; }
}

The following exception is thrown when calling this function by POSTMAN despite the function works fine out of the docker context e.g. VS 2022. Please note that there is a reverse proxy in place to accommodate CORS that performs well as other functions are working properly.

Exceptions (if any)

myfunction | info: Function.AddToGroup[1] myfunction | Executing 'Functions.AddToGroup' (Reason='This function was programmatically called via the host APIs.', Id=c9487a71-046c-4bdb-bab5-85037718ce31) myfunction | fail: Function.AddToGroup[3] myfunction | Executed 'Functions.AddToGroup' (Failed, Id=c9487a71-046c-4bdb-bab5-85037718ce31, Duration=6ms) myfunction | Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.AddToGroup myfunction | ---> Microsoft.Azure.SignalR.Common.ServiceConnectionNotActiveException: The connection is not active, data cannot be sent to the service. myfunction | at Microsoft.Azure.SignalR.ServiceConnectionContainerBase.WriteWithRetry(ServiceMessage serviceMessage, Int32 initial, Int32 count) myfunction | at Microsoft.Azure.WebJobs.Extensions.SignalRService.AzureSignalRClient.AddUserToGroup(String userId, String groupName) myfunction | at Microsoft.Azure.WebJobs.Extensions.SignalRService.SignalRAsyncCollector1.AddAsync(T item, CancellationToken cancellationToken) myfunction | at Microsoft.Azure.WebJobs.Script.Binding.FunctionBinding.BindAsyncCollectorAsync[T](BindingContext context) in /src/azure-functions-host/src/WebJobs.Script/Binding/FunctionBinding.cs:line 199 myfunction | at Microsoft.Azure.WebJobs.Script.Binding.ExtensionBinding.BindAsync(BindingContext context) in /src/azure-functions-host/src/WebJobs.Script/Binding/ExtensionBinding.cs:line 84 myfunction | at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.<>c__DisplayClass13_0.<<BindOutputsAsync>b__0>d.MoveNext() in /src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 170 myfunction | --- End of stack trace from previous location --- myfunction | at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.BindOutputsAsync(Object input, Binder binder, ScriptInvocationResult result) in /src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 174 myfunction | at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 98 myfunction | at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /src/azure-functions-host/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82 myfunction | at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task1 src) in /src/azure-functions-host/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225 myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52 myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 596 myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 542 reverseproxy | 172.18.0.1 - - [22/Feb/2022:20:06:19 +0000] "GET /api/addtogroup/MyGroup/MyId HTTP/1.1" 500 0 "-" "PostmanRuntime/7.29.0" "-" myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 320 myfunction | --- End of inner exception stack trace --- myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 367 myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 108 myfunction | fail: Host.Results[0] myfunction | Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.AddToGroup myfunction | ---> Microsoft.Azure.SignalR.Common.ServiceConnectionNotActiveException: The connection is not active, data cannot be sent to the service. myfunction | at Microsoft.Azure.SignalR.ServiceConnectionContainerBase.WriteWithRetry(ServiceMessage serviceMessage, Int32 initial, Int32 count) myfunction | at Microsoft.Azure.WebJobs.Extensions.SignalRService.AzureSignalRClient.AddUserToGroup(String userId, String groupName) myfunction | at Microsoft.Azure.WebJobs.Extensions.SignalRService.SignalRAsyncCollector1.AddAsync(T item, CancellationToken cancellationToken) myfunction | at Microsoft.Azure.WebJobs.Script.Binding.FunctionBinding.BindAsyncCollectorAsync[T](BindingContext context) in /src/azure-functions-host/src/WebJobs.Script/Binding/FunctionBinding.cs:line 199
myfunction | at Microsoft.Azure.WebJobs.Script.Binding.ExtensionBinding.BindAsync(BindingContext context) in /src/azure-functions-host/src/WebJobs.Script/Binding/ExtensionBinding.cs:line 84 myfunction | at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.<>c__DisplayClass13_0.<b__0>d.MoveNext() in /src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 170 myfunction | --- End of stack trace from previous location --- myfunction | at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.BindOutputsAsync(Object input, Binder binder, ScriptInvocationResult result) in /src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 174 myfunction | at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 98 myfunction | at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /src/azure-functions-host/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82 myfunction | at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task1 src) in /src/azure-functions-host/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225 myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52 myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 596 myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 542 myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 320 myfunction | --- End of inner exception stack trace --- myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 367 myfunction | at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 108

Further technical details

    <ItemGroup>
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.7.0-preview1" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.SignalRService" Version="1.2.2" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
        <PackageReference Include="Microsoft.Azure.Core.NewtonsoftJson" Version="1.0.0" />
    </ItemGroup>

.NET info is per below:

.NET SDK (reflecting any global.json): Version: 6.0.102 Commit: 02d5242ed7

Runtime Environment: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.102\

Host (useful for support): Version: 6.0.2 Commit: 839cdfb0ec

.NET SDKs installed: 3.1.416 [C:\Program Files\dotnet\sdk] 6.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Arash-Sabet commented 2 years ago

@Y-Sindo just wondering, is this a question that you may know the answer? Thanks.

Y-Sindo commented 2 years ago

Microsoft.Azure.SignalR.Common.ServiceConnectionNotActiveException: The connection is not active, data cannot be sent to the service.

Your function host didn't successfully establish WebSocket connection with Azure SignalR Service. There might be some network issues in your container. You could enable Debug log level to check the logs when the host was trying to connect to SignalR Service to see why.