All Products
Search
Document Center

Function Compute:What do I do if the client is disconnected and the message "Invocation canceled by client" is reported?

Last Updated:Feb 01, 2024

This topic describes the causes of and solutions to the "Invocation canceled by client" error.

Problem description

The following error message is reported in the request log when a function is invoked from the client to process a request:

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 execution of the function is interrupted and an error is reported.

Solution

Follow the following steps to resolve the issue:

  1. Check the duration of function execution when the client canceled the request based on the error returned.

    In this example, duration: 4912ms indicates that the function runs for approximately 5 seconds.

  2. Determine whether the execution time meets your expectations based on your business requirements.

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 configure 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 of the service in the Function Compute console.

    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 Function Compute 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

In most cases, the execution duration of a program is determined by the following operations:

  • 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 you access an external service to check whether the time consumed to access external services is normal.

  • Computing operations

    A large number of computing operations may also increase the latency. We recommend that you increase the CPU specifications.