This topic describes the causes of and solutions to the "Invocation canceled by client" error.
Problem description
FC Invoke End RequestId: 1-64263a4b-2cd7c98b677*********, Error: Invocation canceled by client (duration: 4912ms, maxMemoryUsage: 0.00MB)
Cause
The client that initiated the invocation canceled the request. As a result, the execution of the function is interrupted and an error is reported.
Solution
Follow the following steps to troubleshoot the issue:
- Check the duration of function execution when the client canceled the request based on the error log.
In this example,
duration: 4912ms
indicates that the function runs for approximately 5 seconds. - Determine whether the execution time meets expectations based on your business requirements.
- If the execution duration meets the expectation, increase the timeout period of the client. For more information, see Execution duration as expected.
- If the execution duration does not meet your expectations, you must check the execution logic of the function based on the logs to identify the parts that lead to the increase of execution duration. For more information, see Execution duration not as expected.
Execution duration as expected
- If you invoke a function by using an SDK or API operation, we recommend that you set the request timeout period to a value greater than the configured timeout period of the function.
For example, if you use the Golang language and invoke the function by using the Function Compute API, you can set the request timeout period by using the Timeout property in the http.Client. If context.Context is used when you initiate a request, you can adjust the deadline or timeout period of the context.
- If you call a function by using another service, you can modify the backend timeout period in the console of the service.
For example, if you use an API operation to invoke a function in the frontend, you can modify the backend timeout settings of the API operation in the API Gateway console. For more information, see Create an API.
- If you call a function in the console, do not click Cancel Request to cancel the request or close the web page before the function is executed.
Execution duration not as expected
- I/O operations
I/O operations, especially network I/O operations, are the main cause of increased execution latency. We recommend that you add logs before and after accessing an external service to check whether the time consumed to access the external service is normal.
- Computing operations
A large number of computing operations may also increase the latency. We recommend that you increase the CPU specifications.