-2

I have created an Azure Function in Go. The function is working properly in local machine with GET & POST requests. When published, request payload sent via POST is not available in the request object. Here's my code:

# Main function
mux := http.NewServeMux()
mux.HandleFunc("/hello", helloWorld)
logrus.Fatal(http.ListenAndServe(":"+httpInvokerPort, mux))

# helloWorld function
func helloWorld(w http.ResponseWriter, r *http.Request) {
    logrus.Info("hello: inside helloWorld")

    bodyBuffer, err := ioutil.ReadAll(r.Body)
    if err != nil {
        logrus.Info("error while reading:" + err.Error())
        w.Write([]byte("GO: error in reading request body"))
    } else {
        logrus.Info("body : " + string(bodyBuffer))

        w.Write([]byte("GO: return hello"))
    }
}

After deployment, I invoke a POST api request with following JSON body:

{ 
    "a": "b"
}

In the logs, i see:

time="2020-07-31T01:14:11Z" level=info msg="body : "

function.json:

{
    "bindings": [
        {
            "authLevel": "anonymous",
            "type": "httpTrigger",
            "direction": "in",
            "name": "req",
            "methods": ["get", "post"]
        },
        {
            "type": "http",
            "direction": "out",
            "name": "res"
        }
    ]
}

My code is hosted here: https://github.com/mpurusottamc/azurefunc-go

Any suggestions on how to debug this?

Puru
  • 373
  • 1
  • 15
  • What does `formatRequest` do and why are you ignoring errors while reading the request body? – Volker Jul 31 '20 at 06:36
  • @Volker I have updated the code to remove formatRequest. formatRequest function was used to print request header values. Even after the update, i see the same log entry. I don't see any error logs. – Puru Jul 31 '20 at 16:09
  • @Volker I have updated the error handling code as well – Puru Jul 31 '20 at 16:23

1 Answers1

0

It is an issue with Windows OS based Function Apps. When i updated the OS type to Linux, i started receiving the request payload.

Here's my functionapp creation command:

az functionapp create --resource-group hellogogrplinux --os-type Linux --consumption-plan-location eastus --runtime node --runtime-version 10 --functions-version 3 --name hellogoapplinux --storage-account hellogostglinux

Here's my updated log:

time="2020-08-06T03:21:38Z" level=info msg="body : {\n \"a\": \"b\"\n}"

This is a known issue on Azure Functions host and is resolved now. Would be rollout this week as part of runtime version: 3.0.14251

There are more details at this github issue: https://github.com/Azure/azure-functions-host/issues/6444

Puru
  • 373
  • 1
  • 15