Azure function app in Rust failing Http Worker, connection refused

I’m trying to deploy an azure function app (http trigger) implemented in Rust. I have created a function app using custom handler and try to read the port number from
the environment variable FUNCTIONS_CUSTOMHANDLER_PORT

let port_key = "FUNCTIONS_CUSTOMHANDLER_PORT";
    let port: u16 = match env::var(port_key) {
        Ok(val) => val.parse().expect("Custom Handler port is not a number!"),
        Err(_) => 7071,
    };

However, the function app doesn’t start properly, and the logs are full of messages like this:
Waiting for HttpWorker to be initialized. Request to: http://127.0.0.1:42353/ failing with exception message: Connection refused (127.0.0.1:42353)

I can’t find the variable FUNCTIONS_CUSTOMHANDLER_PORT in either the Function app setup in azure portal or in the list of env vars in Kudu. Do anyone know what I might need to do to make this variable available for the function app?

1

Make sure Custom handler is configured correctly in host.json and validate the configurations in function app.
Configure the Azure Application Insights in Azure Functions to analyze the error messages about why the connection is being refused.

I have created a Rust Azure function and deployed to Azure, referred MSDOC.

Code Snippet:

#[tokio::main]
async fn main() {
    let example1 = warp::get()
        .and(warp::path("api"))
        .and(warp::path("HttpTrigger"))
        .and(warp::query::<HashMap<String, String>>())
        .map(|p: HashMap<String, String>| match p.get("name") {
            Some(name) => Response::builder().body(format!("Hello, {}. This HTTP triggered function executed successfully.", name)),
            None => Response::builder().body(String::from("This HTTP triggered function executed successfully. Pass a name in the query string for a personalized response.")),
        });

    let port_key = "FUNCTIONS_CUSTOMHANDLER_PORT";
    let port: u16 = match env::var(port_key) {
        Ok(val) => val.parse().expect("Custom Handler port is not a number!"),
        Err(_) => 3000,
    };

    warp::serve(example1).run((Ipv4Addr::LOCALHOST, port)).await
}

host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  },
  "customHandler": {
    "description": {
      "defaultExecutablePath": "handler",
      "workingDirectory": "",
      "arguments": []
    },
    "enableForwardingHttpRequest": true
  }
}

Follow the steps provided in MSDOC to compile the custom handler for Azure before deploying the function to Linux Azure function app.

Added FUNCTIONS_CUSTOMHANDLER_PORT=<PortNumber> under Function App=>Settings=>Environment Variables=>App Settings.

Check if the updated App settings are available in the KUDU site(https://functionapp.scm.azurewebsites.net)=> App Settings:

Deployed the function to Azure using Visual Studio.

Able to run the function in portal:

2024-09-16T12:59:03Z   [Information]   Executing 'Functions.HttpTrigger' (Reason='This function was programmatically called via the host APIs.', Id=b3ff7d0b-ae4b-4060-af60-2791b59f5fbc)
2024-09-16T12:59:03Z   [Verbose]   Sending invocation id: 'b3ff7d0b-ae4b-4060-af60-2791b59f5fbc
2024-09-16T12:59:03Z   [Verbose]   Forwarding httpTrigger invocation for function: 'HttpTrigger' invocationId: 'b3ff7d0b-aeXX9f5fbc'
2024-09-16T12:59:03Z   [Verbose]   Sending invocation for function: 'HttpTrigger' invocationId: 'b3ff7d0b-ae4b-XX5fbc'
2024-09-16T12:59:03Z   [Verbose]   Received invocation response for function: 'HttpTrigger' invocationId: 'b3ff7d0b-aXXX1b59f5fbc'
2024-09-16T12:59:03Z   [Information]   Executed 'Functions.HttpTrigger' (Succeeded, Id=b3ff7d0b-ae4b-4060-af60-2791b59f5fbc, Duration=18ms)

Recognized by Microsoft Azure Collective

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật