durabletask-dotnet: DurableTaskClient throwing RpcException "An attempt was made to access a socket in a way forbidden by its access permissions"
It appears that randomly, running in our Azure live environment, most (any?) calls made using the DurableTaskClient are failing with an RpcException:
Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="Error connecting to subchannel.", DebugException="System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions.")
---> System.Net.Sockets.SocketException (10013): An attempt was made to access a socket in a way forbidden by its access permissions.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
at Grpc.Net.Client.Balancer.Internal.SocketConnectivitySubchannelTransport.TryConnectAsync(ConnectContext context)
--- End of inner exception stack trace ---
at Grpc.Net.Client.Balancer.Internal.ConnectionManager.PickAsync(PickContext context, Boolean waitForReady, CancellationToken cancellationToken)
at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)
at Microsoft.DurableTask.Client.Grpc.GrpcDurableTaskClient.GetInstancesAsync(String instanceId, Boolean getInputsAndOutputs, CancellationToken cancellation)
...
If I run the functions app locally (configured to point to the same live environment) I do not get the error.
I haven’t restarted our Azure deployed functions app yet because I opened a support request and wanted them to be able to have a reproducible environment.
Azure Support Request ID: 2411070040008596
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (5 by maintainers)
For anyone who stumbles across this and is need of a way to add the [DurableClient] binding dynamically, we found a way by decorating the analyzer-generated “GeneratedFunctionMetadataProvider” and replacing the singleton in the DI container
This gets the correct source binding in IFunctionBindingsFeature.InputData needed to construct a DurableTaskClient with the correct grpc configuration.
This is frustrating. @cgillum what’s the use case for
Microsoft.DurableTask.Client.ServiceCollectionExtensions.AddDurableTaskClientthen if the client it registers can become defunct?We have an application that depends heavily on DurableTaskClient in a services layer, so the client instance must be available via DI. And we have ~100 Functions so manually putting a [DurableClient] binding on each of them isn’t ideal. Is there a way to obtain the correct URL in a middleware without having to touch all the function signatures?
I think the reason for this error is because a
DurableTaskClientobject created using DI in the .NET Isolated worker does not have the correct address information to connect to the host process.By default, instances of
DurableTaskClientare configured to make calls tolocalhost:4001. As it happens, the Functions host process also listens to port 4001 to handle durable client requests. This is why the DI approach sometimes works. However, the host is not guaranteed to listen on port 4001. For example, if that port is occupied by some other process (like an overlapped recycling instance of the host), then a random port is selected instead.The only valid way to create instances of
DurableTaskClientis to use the[DurableClient]binding. When using this binding, theDurableTaskClientobject is always configured to point to the correct port number of the host, even if randomly generated. More information here.It was clearly a mistake for us to default the host to port 4001 because that incorrectly encourages people to fall into this trap. We may change this in the future, so everyone is strongly encouraged to use the
[DurableClient]approach to ensure that their apps work reliably.