This topic describes common errors in custom runtimes and how to troubleshoot the errors.
Failed to start a function instance
Example
The function cannot be started. Failed to start function instance. Error: the file /code/bootstrap is not existTroubleshooting
A function instance may fail to be started due to an exception that occurred in the startup command or the absence of the startup command.
By default, Function Compute uses
/code/bootstrapas the startup command if the Startup Command parameter is not configured. If the file is not contained in the code package, you can add the/code/bootstrapscript or modify the Startup Command parameter.If the Startup Command parameter is configured, check whether the specified file exists by referring to the error message, which may indicate that the file does not exist (example: "
Error: the file xxx is not exist").
For more information about how to configure Startup Command, see Principles.
Function instance health check failed
Example
Function instance health check failed on port 9001 in 120 seconds.\nLogs:Troubleshooting
If a function instance fails to pass the health check, a possible cause is that the listening IP address or port that is specified in the code is incorrect. After a function instance is started, Function Compute performs a Layer-4 connectivity check based on the port configured for the function. If the check fails within the timeout period, a "Function instance health check failed" error is reported.
To avoid this issue, ensure that the listening IP address and port meet the following requirements:
Listening IP address
The listening IP address that is configured in the code must be
0.0.0.0or*, and cannot be set to127.0.0.0orlocalhost.Listening port
The listening port must be the same as the listening port that is configured for the function. The default listening port for a custom runtime is
9000.If you use the default port, make sure that the port on which the HTTP server listens in the code is also
9000.If you have configured the Listening Port parameter for your function, make sure that the port on which the HTTP server listens in the code is consistent with the value of Listening Port.
For more information about how to configure Listening Port, see Requirements for HTTP server configurations.
Function instance exited unexpectedly
Example
Function instance exited unexpectedly(code 2, message:no such file or directory) with start command '/code/bootstrap '.
Logs:Function instance exited unexpectedly: A function instance unexpectedly exited.code 2, message:no such file or directory: The Linux exit code of the instance startup process and description of the code.with start command '/code/bootstrap ': The startup command of the instance.
The exit code and the description of the exit code are provided only for reference. In some cases, the code does not carry the conventional meaning in any way.
Troubleshooting
No executable permissions for the startup command
The function cannot be started. Function instance exited unexpectedly(code 13, message:permission denied) with start command '/code/bootstrap '.In most cases,
code 13, message:permission deniedis reported if no executable permissions are configured for the instance startup command. You can run thechmod 755 bootstrap,chmod 777 bootstrap, orchmod +x bootstrapcommand to grant the executable permissions to the file before you package the code.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:xxxIn most cases,
code 2, message:no such file or directoryis reported if the file in the startup parameters does not exist. In some cases,code 2, message:no such file or directorymay not be reported. In these cases, you must troubleshoot the error based on error logs.The following section describes the error messages that are returned for different programming languages when the file specified in the startup command does not exist.
Invalid file format
Function instance exited unexpectedly(code 8, message:exec format error) with start command '/code/bootstrap '. Logs:A custom runtime runs on
x86-64-based Linux. Make sure that your startup files are compatible with the system environment. If the startup command is a shell script, make sure that the file follows the Linux syntax and includes the#!line (shebang) at the beginning of the script. If the startup command is a binary executable file, make sure that it is an executable and linkable format (ELF) file that is compatible with Linux operating systems. The following section describes the file format errors.Shebang error of shell script in the startup command
In most cases,
8 exec format erroris reported as the exit code if the shell script lacks a valid shebang. To avoid the error, you must add a valid shebang to the first line of the shell script.If you want to use bash to run the script, you can add
#!/usr/bin/env bashor#!/bin/bashto the first line of the file. We recommend that you use#!/usr/bin/env bash. By default,/bin/shin a custom runtime is/bin/bash. Therefore, you can run the#!/usr/bin/env shor#!/bin/shcommand.Shell script in startup command in Windows syntax
Run the following test script:
#!/usr/bin/env bash node /code/index.jsThe following error message is returned:
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 directoryThe error log message "
bash\r" indicates that thebashcommand is followed by a carriage return character (\r). This is a characteristic of Windows file syntax, which uses\r\nto denote line breaks, whereas Unix files use\n. Therefore, it is likely that the file was created on a Windows system and follows Windows syntax.If you create your script on a Windows OS, you must convert it to a format compatible with UNIX OSs. You can run the
dos2unixcommand in a Linux OS or use WebIDE of Function Compute to convert the script. For more information, see How to convert file formats by using WebIDE provided by Function Compute?A binary executable file used as the startup command
If the startup command is an executable file, make sure that it is an ELF file, which is compatible with Linux OSs. For example, if you compile Golang code on a Mac that is equipped with M1 chips by using the default configuration
GOOS=darwin GOARCH=arm64, the following error message is reported after the code is packaged, uploaded, and tested: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 that the file format is invalid. You must addGOOS=linux GOARCH=amd64during the compilation. For more information, see Compile and deploy code packages.
Common exit codes
The following section describes other common exit codes.
Exit Code 137
The program receives SIGKILL and exceptionally exits. In most case, this issue is caused by
OOMKilled(Out of Memory). In this case, you can upgrade the memory configuration for the function.
Additional information
If any error that is not listed in this topic occurs, see Custom Runtime FAQ.