Skip to main content

Cloud Function Runtime Node.js16 ETIMEDOUT Issue

In the Cloud Functions runtime, the operational mechanism of the Node.jsV16 version has been modified, which may lead to ETIMEDOUT issues.

Symptom

The function execution fails, and the error messages contain ETIMEOUT, ESOCKETTIMEOUT, etc., with the function execution time being only a few milliseconds.

Cause of the Issue

When an asynchronous callback is triggered, it may be chained into a subsequent invocation. If an exception is thrown in the asynchronous callback, the runtime will catch this uncaughtException error, consider it as an issue in the current cloud function invocation, and return the exception as the execution result of the cloud function.

Reproduction Code

function nowISOString() {
return new Date().toISOString()
}

exports.main = async function (event, context) {
console.log('request start', context.request_id, nowISOString())
setTimeout(() => {
throw new Error('ETIMEDOUT' + context.request_id)
}, 6000)
console.log('request finish', context.request_id, nowISOString())

await new Promise((resolve) => {
setTimeout(() => {
resolve()
}, 3000)
})
return 'success'
}

Resolution

  1. Use v10 or v12 versions: If possible, it is recommended to use Node.js v10 or v12 versions.
  2. Check asynchronous code: Check for any asynchronous calls without await in the code and ensure all asynchronous operations are properly awaited.

More Information

The runtime for cloud functions in Node.js 14.18, Node.js 16.13, and other versions has changed, no longer supporting certain asynchronous features. The current timeout errors may occur due to asynchronous tasks without await in the function code that continue running after the function returns, potentially causing issues in subsequent invocations.

For more detailed information, please refer to: Cloud Function Exception Handling Documentation

Similar Issues

  • What causes the ETIMEDOUT issue in the Node.js16 runtime of cloud functions?
  • How to resolve the ETIMEDOUT issue in the Node.js16 runtime of cloud functions?
  • How to handle the ETIMEOUT error in the Node.js16 runtime of cloud functions?
  • How to resolve the ETIMEDOUT issue caused by asynchronous calls in cloud functions?
  • Why does the Node.js16 runtime of cloud functions experience ETIMEDOUT issues?
  • What is the reproduction code for the ETIMEDOUT issue in the Node.js16 runtime of cloud functions?
  • What are the solutions for the ETIMEDOUT issue in the Node.js16 runtime of cloud functions?
  • Which asynchronous features no longer supported in the Node.js16 runtime of cloud functions cause ETIMEDOUT?
  • How to avoid the ETIMEDOUT issue in the Node.js16 runtime of cloud functions?
  • Where can I find detailed documentation regarding the ETIMEDOUT issue in the Node.js16 runtime of cloud functions?