Identify and resolve common errors in the custom runtime environment, including instance startup failures, health check failures, and unexpected process exits.
Instance startup failure (Failed to start function instance)
Error example
The function cannot be started. Failed to start function instance. Error: the file /code/bootstrap is not exist
Troubleshooting
This error typically occurs when the start command is invalid or does not exist.
-
If you do not set the Startup Command, Function Compute uses
/code/bootstrapas the default start command. If this file is not in your code package, you can add the/code/bootstrapscript or modify the Startup Command. -
If you set the Startup Command, check the error message
Error: the file xxx is not existto confirm whether the file exists.
For more information about how to set the Startup Command, see Basic principles.
Instance health check failure (Function instance health check failed)
Error example
Function instance health check failed on port 9001 in 120 seconds.\nLogs:
Troubleshooting
This error typically occurs when the listening IP address or port is incorrectly configured. After the function instance starts, the platform runs a Layer 4 connectivity check on the configured port. If the check fails within the timeout period, the Function instance health check failed error is returned.
The listening address and port must meet the following conditions.
-
Listening address
The listening IP address in the code must be set to
0.0.0.0or*. It cannot be set to127.0.0.0orlocalhost. -
Listening port
The listening port must be the same as the port in the function configuration. The default listening port for a custom runtime is
9000.-
If you use the default port, make sure the port that the HTTP server listens on in the code is also
9000. -
If you set the Listening Port, make sure the port that the HTTP server listens on in the code is the same.
-
For more information about how to set the Listening Port, see HTTP Server configuration requirements.
Instance process exits unexpectedly (Function instance exited unexpectedly)
Error example
Function instance exited unexpectedly(code 2, message:no such file or directory) with start command '/code/bootstrap '.
Logs:
-
Function instance exited unexpectedlyindicates that the instance startup process exited unexpectedly. -
code 2, message:no such file or directoryindicates the Linux exit code of the instance startup process and its meaning. -
with start command '/code/bootstrap 'indicates the start command of the instance.
Process exit codes are for reference only. They do not definitively indicate the cause of the exit, because your application code may set custom exit codes that differ from standard Linux exit code meanings.
Troubleshooting
-
The start command does not have execute permissions
The function cannot be started. Function instance exited unexpectedly(code 13, message:permission denied) with start command '/code/bootstrap '.If the instance start command does not have execute permissions, the exit code in the error message is usually
code 13, message:permission denied. Before you package the code, you can runchmod 755 bootstrap,chmod 777 bootstrap, orchmod +x bootstrapto grant execute permissions to the file. -
File does not exist
Function instance exited unexpectedly(code 2, message:no such file or directory) with start command 'python3 not_exist_file.py '. Logs:xxxIf a file specified in the start parameters does not exist, the exit code is usually
code 2, message:no such file or directory. In some cases, the exit code may differ fromcode 2, message:no such file or directoryor may be absent. If so, troubleshoot based on the error log.The following sections show error messages for missing files with different start commands.
-
-
Incorrect file format
Function instance exited unexpectedly(code 8, message:exec format error) with start command '/code/bootstrap '. Logs:The custom runtime runs on Linux with
x86-64architecture. Ensure your startup file is compatible with this environment. If the start command is a shell script, the file must be in Linux format and include a shebang line (#!). If the start command is a binary executable, the file must be in ELF format. Details are as follows.-
Incorrect shebang line in the start command shell script
When a shell script is missing the shebang line at the beginning or the shebang line is incorrect, the instance exit code is usually
8 exec format error. Therefore, you must add the correct shebang line to the beginning of the file.To run the script using Bash, you can add the command
#!/usr/bin/env bashor#!/bin/bashto the first line of the file. We recommend that you use#!/usr/bin/env bash. In the custom runtime environment,/bin/shdefaults to/bin/bash. Therefore, you can also use the command#!/usr/bin/env shor#!/bin/sh. -
The start command shell script is in Windows format
Run the following test script.
#!/usr/bin/env bash node /code/index.jsThe following error is reported.
Function instance exited unexpectedly(code 127, message:key has expired) with start command '/code/bootstrap '. Logs:/usr/bin/env: ‘bash\r’: No such file or directoryIn the error log,
bash\rindicates that there is an extra\rcharacter afterbash. The line feed for Unix files is\n, while the line feed for Windows files is\r\n. This indicates that the file is in Windows format.If your script was created in Windows, you must convert the script format to Unix. You can run the
dos2unixcommand in a Linux system to perform the conversion, or use the Function Compute WebIDE. For more information, see How do I use the Function Compute WebIDE to convert file formats?. -
The start command is a binary executable file
If the start command is an executable file, ensure that the file is in the ELF format, which is compatible with Linux systems. For example, if you compile Golang code on a Mac with an M1 chip using the default configurations
GOOS=darwin GOARCH=arm64, and then package, upload, and test the code, the following error message is reported.Function instance exited unexpectedly(code 8, message:exec format error) with start command './main '. Logs:The instance exit code is
8 exec format error, which indicates an incorrect file format. You must add theGOOS=linux GOARCH=amd64configuration at compile-time. For more information, see Compile and deploy a code package.
-
-
Common exit codes
Other common exit codes and their causes are as follows.
-
Exit Code 137
The program received a SIGKILL signal and exited unexpectedly. This is typically an
OOMKilled (Out of Memory)issue caused by insufficient memory. To resolve this, increase the memory size of the function.
-
More information
If your error is not listed in this topic, see Custom Runtimes FAQ for additional troubleshooting guidance.