question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timeout value of 00:05:00 was exceeded by function: Functions.MyFunc.

See original GitHub issue

I’m trying to setup a function app using script, steps are listed below.

Repro steps

Provide the steps required to reproduce the problem

  1. Create dynamic function app using json template

  2. Setting environment variable (some connection string) through Azure CLI 2.0

  3. Create a folder as a function name under site/wwwroot/ (Kudu REST API)

  4. Upload files into the created folder (through FTP)

  5. run “npm install” (Kudu REST API)

My function code:

'use strict';

const Client = require('azure-iothub').Client;
const Message = require('azure-iot-common').Message;
const iotHubConnectionString = process.env['speech-recognition-iothub'];

module.exports = function (context, myEventHubMessage) {
    context.log(myEventHubMessage);
    if (myEventHubMessage.DeviceID) {
        const cloudClient = Client.fromConnectionString(iotHubConnectionString);
        cloudClient.open(function (err) {
            if (err) {
                console.log('Could not connect: ' + err.message);
            } else {
                console.log('Client connected');
                const message = new Message(`Pong - ${new Date().toTimeString()}`);
                cloudClient.send(myEventHubMessage.DeviceID, message, function (err, res) {
                    if (err) {
                        context.log(`Error in send C2D message: ${err}`);
                    } else {
                        context.log(`send status: ${res.constructor.name}`);
                    }
                });
            }
            context.done();
        });
    }
};

Actual behavior

Then I send some msg to my IoT Hub. The function app is keeping logging “function app start”

logs can be seen here,

Actually, if I do nothing, the function app still keeps logging “function app start”

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tohlingcommented, Apr 11, 2017

@jdneo, could you try changing your Function to process the EventHub messages in batches? You can do so with the following 2 steps:

  1. Add “cardinality”: “many” as a new property in your input binding in your function.json file.
  2. Encapsulate your Function code in a FOR-loop to process an array of events instead. I changed the name of your input-binding to myEventHubMessages to indicate plurality.
'use strict';

const Client = require('azure-iothub').Client;
const Message = require('azure-iot-common').Message;
const iotHubConnectionString = process.env['speech-recognition-iothub'];

// renamed your input-binding to myEventHubMessages
module.exports = function (context, myEventHubMessages) {
  context.log(util.format("Node.js script processed %d events", myEventHubMessages.length));
  context.log("IsArray", util.isArray(myEventHubMessages));
  const cloudClient = Client.fromConnectionString(iotHubConnectionString);

  cloudClient.open(function (err) {
  if (err) {
    context.log('Could not connect: ' + err.message);
  } else {
    context.log('Client connected');
    for (i = 0; i < myEventHubMessages.length; i++)  
	{
      context.log(myEventHubMessages[i]);
      if (myEventHubMessages[i].DeviceID) {
        const message = new Message(`Pong - ${new Date().toTimeString()}`);
		cloudClient.send(myEventHubMessages[i].DeviceID, message, function (err, res) {
		  if (err) {
		    context.log(`Error in send C2D message: ${err}`);
		  } else {
		    context.log(`send status: ${res.constructor.name}`);
		  }
		});	
	  }
	}	
  }
	
  cloudClient.close()// not sure if this is the syntax in Node for cloudClient
  context.done();
};

A similar Function setup can be found at: https://github.com/Azure/azure-webjobs-sdk-script/tree/dev/sample/EventHubTrigger

0reactions
jdneocommented, Apr 12, 2017

Thank you guys! According to your suggestion, I figure out the mistakes I made:

  1. context.done() should be ensured to be called

e.g.

cloudClient.open(function (err) {
    if (err) {
        // error handler
        context.done()
    } else {
        //success handler
        context.done()
    }
});

Put the context.done() inside the callback function can make the ‘function complete’ log always show in the last step of the function execution

  1. cloudClient.close() should be called. In my investigation, if cloudClient.close() is not called, it will encounter some problems to open the client in the next function trigger.

Thank you again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timeout value of 00:05:00 was exceeded by function in ...
Azure Functions are now allowed to run upto 10 minutes. You need to change the "functionTimeout" value in host.json file.
Read more >
Azure Functions: Timeout value of 00:05:00 exceeded by ...
When running Azure functions, I encountered the following error: 2021-09-17T08:13:47.525 [Error] Timeout value of 00:05:00 exceeded by ...
Read more >
Azure function not running successfully. - Microsoft Q&A
Host: Timeout value of 00:05:00 was exceeded by function: 'MY_FUNCTION_NAME.' For the above error, I have raised the timeout value from default ......
Read more >
Timeout value of 00:30:00 exceeded by function
Hello everyone, I have a function in azure that saves the Exchange messagetarce however in some cases the duration time is greater than...
Read more >
Azure Functions: Extend Execution Timeout Past 5 Minutes
json I have given timeout value to 2 hours, but it was failing with error “Timeout value of 02:00:00 was exceeded by function:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found