Debug Your Infrastructure

Get Instant Solutions for Kubernetes, Databases, Docker and more

AWS CloudWatch
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Pod Stuck in CrashLoopBackOff
Database connection timeout
Docker Container won't Start
Kubernetes ingress not working
Redis connection refused
CI/CD pipeline failing

Firebase (sdk) Cloud Function execution is unexpectedly cancelled.

The Cloud Function execution was cancelled due to an external trigger or timeout.

Understanding Firebase Cloud Functions

Firebase Cloud Functions is a serverless framework that allows developers to run backend code in response to events triggered by Firebase features and HTTPS requests. It is designed to scale automatically, ensuring that your application can handle varying loads without manual intervention. Cloud Functions are particularly useful for executing code in response to changes in your Firebase Realtime Database, Firestore, Authentication, and more.

Identifying the Symptom

When working with Firebase Cloud Functions, you might encounter the error code functions/cancelled. This error indicates that the execution of a Cloud Function was unexpectedly cancelled. Developers often notice this issue when their function does not complete its intended task, and logs show a cancellation error.

Common Observations

  • Function logs indicate a cancellation error.
  • Expected outputs or side effects of the function are not observed.
  • Function execution time is shorter than expected.

Exploring the Issue

The functions/cancelled error occurs when a Cloud Function is terminated before it completes its execution. This can happen due to several reasons, such as:

  • Timeouts: The function exceeds the maximum execution time.
  • Manual cancellations: An external process or user cancels the function.
  • Resource constraints: The function is terminated due to resource limitations.

Understanding the root cause is crucial for resolving this issue effectively.

Timeouts

By default, Cloud Functions have a maximum execution time of 60 seconds for HTTP functions and 540 seconds for background functions. If your function takes longer, it will be cancelled. Consider optimizing your code or increasing the timeout setting if necessary.

Steps to Fix the Issue

To resolve the functions/cancelled error, follow these steps:

1. Review Function Logs

Check the function logs in the Firebase Console to identify patterns or specific triggers that lead to the cancellation. This can provide insights into whether the issue is due to timeouts or other factors.

Learn more about viewing logs.

2. Optimize Function Code

Ensure that your function code is optimized for performance. Avoid unnecessary computations and external API calls that can increase execution time. Consider breaking down complex tasks into smaller, more manageable functions.

3. Adjust Timeout Settings

If your function legitimately requires more time to execute, consider increasing the timeout setting. You can do this by specifying the timeoutSeconds option when deploying your function:

exports.myFunction = functions.runWith({ timeoutSeconds: 300 }).https.onRequest((req, res) => {
// Your function code here
});

Learn more about modifying timeouts.

4. Monitor Resource Usage

Ensure that your function is not exceeding resource limits. You can adjust memory allocation to provide more resources if needed:

exports.myFunction = functions.runWith({ memory: '512MB' }).https.onRequest((req, res) => {
// Your function code here
});

Learn more about modifying memory allocation.

Conclusion

By understanding the potential causes of the functions/cancelled error and following the steps outlined above, you can effectively troubleshoot and resolve this issue. Regularly monitoring your function's performance and resource usage will help prevent future occurrences.

Master 

Firebase (sdk) Cloud Function execution is unexpectedly cancelled.

 debugging in Minutes

— Grab the Ultimate Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Real-world configs/examples
Handy troubleshooting shortcuts
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

Firebase (sdk) Cloud Function execution is unexpectedly cancelled.

Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Your email is safe thing.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

MORE ISSUES

Deep Sea Tech Inc. — Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid