What do I do if the client disconnects and the "Invocation canceled by client" error is reported?
Fix the "Invocation canceled by client" error by finding out why the client canceled the request and applying the matching solution.
Symptoms
The following error message appears in the request log:
FC Invoke End RequestId: 1-64263a4b-2cd7c98b677*********, Error: Invocation canceled by client (duration: 4912ms, maxMemoryUsage: 0.00MB)
Possible causes
The client that initiated the invocation canceled the request. As a result, the function execution was interrupted abnormally and the function returned an error.
Solutions
Follow these troubleshooting steps:
-
Based on the error log, determine how long the function had been running when the client canceled the request.
In the example in this topic,
duration: 4912msindicates that the function had run for nearly 5s. -
Based on your workload, determine whether this execution duration meets expectations.
-
If the execution duration meets expectations, increase the client-side timeout period. For details, see The function execution duration meets expectations.
-
If the execution duration does not meet expectations, use the logs to troubleshoot the function execution path and identify which part of the logic increased the execution time. For details, see The function execution duration does not meet expectations.
-
The function execution duration meets expectations
-
If you invoke the function by using an SDK or API, set the request timeout period to a value greater than the timeout period configured for the function.
For example, if you use Golang and the Function Compute API to invoke a function, set the request timeout period by using the Timeout property in http.Client. If you use context.Context when you initiate the request, adjust the deadline or timeout of the Context.
-
If you invoke the function through another service, modify the backend timeout period in the console of that service.
For example, if the frontend invokes a function through API Gateway, modify the backend timeout setting of the API in the API Gateway console. For instructions, see Create an API.
-
If you invoke the function in the console, do not manually click Cancel Request to cancel the invocation or close the web page before the function finishes execution.
The function execution duration does not meet expectations
Program execution time generally falls into the following two categories:
-
I/O operations
I/O operations, especially network I/O, are the main cause of increased execution latency. Troubleshoot all operations in your program that access external services. Add logs before and after you access an external service to check whether the time consumed is as expected.
-
Compute operations
A large number of compute operations can also increase the latency. Increase the CPU specification.