0

I created a function app using the Azure portal. I checked POST and OPTIONS as allowed methods. I deleted the default CORS settings and allowed *. Now, when I issue an OPTIONS request using a REST client, I get an error returned. I checked the logs and found the following. My question: it sounds like maybe my function is being executed and when no Authorization header and/or no payload is found it throws an error. Maybe I don't understand the OPTIONS request. What are my options for preventing this from happening in the Azure portal function app?

TIA for any help.

2019-05-17T09:16:26.479 [Info] Executing HTTP request: {
  "requestId": "38609669-59f4-4ded-9685-ef67af3c2909",
  "method": "OPTIONS",
  "uri": "/api/ProcessEntries"
}
2019-05-17T09:16:26.479 [Info,ProcessEntries] Function started (Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6)
2019-05-17T09:16:26.479 [Info,ProcessEntries] Executing 'Functions.ProcessEntries' (Reason='This function was programmatically called via the host APIs.', Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6)
2019-05-17T09:16:26.495 [Error] A ScriptHost error has occurred
2019-05-17T09:16:26.495 [Error] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.526 [Error,ProcessEntries] Exception while executing function: Functions.ProcessEntries. Microsoft.Azure.WebJobs.Script: One or more errors occurred. Anonymously Hosted DynamicMethods Assembly: Cannot perform runtime binding on a null reference.
2019-05-17T09:16:26.573 [Error,ProcessEntries] Exception while executing function: Functions.ProcessEntries
2019-05-17T09:16:26.573 [Error,ProcessEntries] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.573 [Error,ProcessEntries] Function completed (Failure, Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6, Duration=87ms)
2019-05-17T09:16:26.573 [Error,ProcessEntries] Executed 'Functions.ProcessEntries' (Failed, Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6)
2019-05-17T09:16:26.573 [Error,ProcessEntries] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.573 [Error,ProcessEntries] Function had errors. See Azure WebJobs SDK dashboard for details. Instance ID is '41b4691d-98ec-432f-8e6e-de1e1dcd13b6'
2019-05-17T09:16:26.573 [Error,ProcessEntries] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.588 [Error] {"id":"eada812b-1530-4d26-85e3-4c6e6e243f01","requestId":"38609669-59f4-4ded-9685-ef67af3c2909","statusCode":500,"errorCode":0,"message":"An error has occurred. For more information, please check the logs for error ID eada812b-1530-4d26-85e3-4c6e6e243f01"}
2019-05-17T09:16:26.588 [Error] Cannot perform runtime binding on a null reference


Denise
  • 61
  • 5
  • If authorization would be the issue, the function should not have been executed at all. It rather sounds like there is an issue with a binding. Are you expecting any parameters in your Function? Can you post you function header / function.json? – silent May 17 '19 at 12:06
  • I don't understand why the options request would be looking for something to bind. I can understand why my function would, yes. It does have connections to some storage account stuff and it does expect a payload. But why would the options request care about any of it? Is it trying to execute the function? – Denise May 17 '19 at 12:50
  • The function.json in multiple comments since there's a text limit: { "bindings": [ { "authLevel": "anonymous", "name": "req", "type": "httpTrigger", "direction": "in", "methods": [ "post", "options" ] }, { "name": "$return", "type": "http", "direction": "out" }, – Denise May 17 '19 at 12:50
  • { "type": "table", "name": "outShazamPayloadsTable", "tableName": "czShazamPayloadsTable", "connection": "czshazam19storageaccount_STORAGE", "direction": "out" }, { "type": "queue", "name": "outputQueueItem", "queueName": "czshazamqueue", "connection": "czshazam19storageaccount_STORAGE", "direction": "out" } ], "disabled": false } – Denise May 17 '19 at 12:51
  • Not sure how to post a follow up to the question instead of a comment. Sorry for the formatting issues. – Denise May 17 '19 at 12:51

2 Answers2

0

Maybe answering my own question (which this isn't really an answer) lets me post a follow-up in a cleaner fashion.

I don't understand why the options request would be looking for something to bind. I can understand why my function would, yes. It does have connections to some storage account stuff and it does expect a payload. But why would the options request care about any of it? Is it trying to execute the function?


{
  "bindings": [
    {
      "authLevel": "anonymous",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "post",
        "options"
      ]
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    },
    {
      "type": "table",
      "name": "outShazamPayloadsTable",
      "tableName": "czShazamPayloadsTable",
      "connection": "czshazam19storageaccount_STORAGE",
      "direction": "out"
    },
    {
      "type": "queue",
      "name": "outputQueueItem",
      "queueName": "czshazamqueue",
      "connection": "czshazam19storageaccount_STORAGE",
      "direction": "out"
    }
  ],
  "disabled": false
}

Denise
  • 61
  • 5
0

In case someone comes across this later...

Turns out the problem was that my function app was being executed even when the OPTIONS request was sent. I did not expect that. And it was bombing because there was no payload sent with it. Due to the nature of the project I knew there would always be a payload with a POST and never considered that the OPTIONS request would also execute that code. Once I put some null checking in my function, all was well and I started receiving status = 200 for OPTIONS requests.

I guess I should have remembered there's never anything that's a sure thing.

Denise
  • 61
  • 5