Error connecting to tcp socket from Azure Functions

Alexey Chirukhin 26 Reputation points
2020-08-27T15:55:58.293+00:00

We have Azure Function configured with VNet integration to our private network.
Also, we have Azure Container Instance with ClamAV application running in our private network.

Using my development machine that is connected to the private network I can connect to the ClamAV application.
But when Azure Function tries to connect to the same ClamAV application it fails with this error: Exception: An attempt was made to access a socket in a way forbidden by its access permissions. [::ffff:172.16.195.196]:3310;

The code looks like this:
var clamAvClient = new TcpClient();
await clamAvClient.ConnectAsync("172.16.195.196", 3310); // <-- exception thorwn here
// send the file data to the tcp client stream

The exact same code works from the dev machine but fails in Azure Function.
Azure Function has access to the private network (it successfully connects to the Blob Storage in this private network).
Azure Function can connect to the different ClamAV application located in the public network.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,261 questions
Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,140 questions
{count} vote

Accepted answer
  1. Pramod Valavala 20,516 Reputation points Microsoft Employee
    2020-09-02T13:51:57.063+00:00

    Looks like you've created the same post on SO and the solution there seems to solve the problem. I was able to reproduce the same problem and while searching for a solution to force IPv4, I found your other thread and the solution from evilSnobu did the trick.

    var clamAvClient = new TcpClient(AddressFamily.InterNetwork);
    
    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful