Azure SDK python client to Azure iothub over HAproxy (SSL handshake failure)

Occasional Visitor

I am trying to fix an IP address for Azure Iothub via Load Balencer and HAproxy as suggested in this solutionConnection architecture I have configured the HAproxy as suggested to pass the SSL handshake to the server:


        log /dev/log    local0
        log /dev/log    local1 notice
        chroot /var/lib/haproxy
        stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
        stats timeout 30s
        user haproxy
        group haproxy

        # Default SSL material locations
        ca-base /etc/ssl/certs
        crt-base /etc/ssl/private

        # Default ciphers to use on SSL-enabled listening sockets.
        # For more information, see ciphers(1SSL). This list is from:
        # An alternative list with additional directives can be obtained from
        ssl-default-bind-options no-sslv3
        log     global
        mode    http
        option  httplog
        option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000
        errorfile 400 /etc/haproxy/errors/400.http
        errorfile 403 /etc/haproxy/errors/403.http
        errorfile 408 /etc/haproxy/errors/408.http
        errorfile 500 /etc/haproxy/errors/500.http
        errorfile 502 /etc/haproxy/errors/502.http
        errorfile 503 /etc/haproxy/errors/503.http
        errorfile 504 /etc/haproxy/errors/504.http frontend haproxy_iothub
        bind *:8883
        bind *:443
        bind *:5671
        mode tcp
        default_backend iothub
backend iothub
        mode tcp
        server iothub [Server URL]:8883 check
        server iothub [Server URL]:443 check
        server iothub [Server URL]:5671 check



To simulate the device, I used Azure V2 SDK (azure-iot-device) and defined a proxy option and created a client from a connection string.



proxy_opts = ProxyOptions(proxy_type=socks.HTTP, proxy_addr="Proxy_ IP", proxy_port=8883)
device_client = IoTHubDeviceClient.create_from_connection_string("IOTHUB_DEVICE_CONNECTION_STRING", websockets=True, proxy_options=proxy_opts )


I was not able to reach the iothub, I tried debugging the library to get more information and it turned out that the blocking occurs due to a general proxy error ("connection closed unexpectedly") in _negotiate_HTTP. socks.HTTPError :504 : Gateway Time-out (in


HAproxy logging showes :


Oct 18 08:48:37 vmss2xigg000000 haproxy[27470]: *..:59000 [18/Oct/2021:08:48:37.451] haproxy_iothub iothub/iothub1 1/1/38 0 -- 1/1/0/0/0 0/0


Any help much appreciated

HA-Proxy version 1.8.8-1ubuntu0.11

Azure-iot-device Version 2.8.0

0 Replies