This error occurs because an instance process unexpectedly exits. The following items list the possible causes. You can troubleshoot the issue based on the corresponding causes.
HTTP server connection actively closed
The HTTP server connection is actively closed. The following items list the possible causes:
The keep-alive mode is not configured for the connection.
The connection is closed after the HTTP server is idle for a period of time.
A read/write operation times out or fails.
Solution
Function Compute uses the keep-alive mode to remain connected to the HTTP server of a custom runtime. For idempotent requests such as GET, HEAD, OPTIONS, and TRACE requests, the system retries to connect to the HTTP server when an error such as EOF or connection reset by peer occurs. For non-idempotent requests such as POST and PATCH requests, 502 errors are returned if the connection fails. To prevent 502 errors, make the following configurations on the HTTP server of the custom runtime:
Set the connection mode to keep-alive.
Disable the idle timeout feature for the HTTP server or set the idle timeout period to more than 15 minutes.
The configurations vary based on the HTTP server frameworks. For example, for the GoFrame framework, you must configure the SetIdletimeout, ReadTimeout, and python uvicorn parameters. You must set the SetIdletimeout parameter to 0, and configure the --timeout-keep-alive parameter in the command line of python uvicorn. We recommend that you check whether the HTTP server is disconnected when sparse invocations are performed by an HTTP client in keep-alive mode.
Function execution exception
The process may exit due to a function exception. The following items list the possible causes:
The
exitinterface is called.The
exceptionsthat occurred during the function execution are not captured.
Sample code: You can add the logging feature and use the logs to debug and troubleshoot the issue.
# -*- coding: utf-8 -*-
import os
import logging
def handler(event, context):
logger = logging.getLogger()
logger.info('something is wrong')
os._exit(-1)
return 'hello world'Solution
Perform the following operations to resolve the issue:
Check whether an active exit logic is specified in your code.
Add exception capture or overwriting mechanisms at the top level of the process in the runtime to prevent processes from exiting when an
exceptionoccurs.
We strongly recommend that you do not use os._exist(-1) in your code to exit a process. Stack information cannot be obtained in Function Compute at the time of exit if you use this method.
We recommend that you use the method of throwing an exception, or manually print stack information to logs before a process exits.
OOM due to insufficient memory
An instance process may exit if an out of memory (OOM) error occurs due to insufficient instance memory. You can analyze request memory usage on the Logs page of the Function Compute console after you enable request-level metric logs. For more information, see Request-level metric logs.
Solution
Log on to the Function Compute console. In the left-side navigation pane, click Functions.
In the top navigation bar, select a region. On the Functions page, click the function that you want to manage.
On the function details page, click the Configurations tab. Then, click Basic Configurations in the left-side navigation pane.
On the Basic Configurations page, click Modify, increase the memory specification, and then click Deploy.
Invalid startup command
The startup command is invalid. The following items list the possible causes:
The startup command does not have the executable permissions.
The file specified by the startup command does not exist.
The format of the file is invalid.
Solution
For more information, see Function instance exited unexpectedly.