This topic describes common error types in the Custom Runtime environment and how to troubleshoot them.
Instance failed to start (Failed to start function instance)
Error example
The function cannot be started. Failed to start function instance. Error: the file /code/bootstrap is not existTroubleshooting
An instance fails to start if the start command is invalid or does not exist.
If you do not set the Start Command, Function Compute uses
/code/bootstrapas the default. If this file is not in your code package, add a/code/bootstrapscript or set the Start Command.If you set the Start Command, check for an error message such as
Error: The file xxx does not existand confirm that the specified file exists.
For more information about setting the Start Command, see Create a function.
Instance failed health check (Function instance health check failed)
Error example
Function instance health check failed on port 9001 in 120 seconds.\nLogs:Troubleshooting
An instance fails the health check, usually because the listening IP address or port is set incorrectly in the code. After the instance starts, the platform performs a Layer 4 connectivity check on the port configured for the function. If the check does not pass within the timeout period, a 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*. Do not set it to127.0.0.0orlocalhost.Listening port
The listening port, which defaults to
9000for a custom runtime, must match the port set in the function configuration.If you use the default port, make sure the HTTP server in your code also listens on port
9000.If you set the Listening Port, make sure the HTTP server in your code listens on the same port.
For more information about setting the Listening Port, see Create a function.
Instance process 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 unexpectedly: The instance startup process exited unexpectedly.code 2, message:no such file or directory: The Linux exit code of the instance startup process and its description.with start command '/code/bootstrap ': The start command for the instance.
The process exit code and its description are for reference only. They do not definitively indicate the reason for the instance exit. The exit code may be custom-defined in your code and may not correspond to the meaning of a standard Linux exit code.
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, grant execute permissions to the file by runningchmod 755 bootstrap,chmod 777 bootstrap, orchmod +x bootstrap.File not found
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 command does not exist, the error message usually includes the exit code
code 2, message:no such file or directory. In some cases, the exit code may not becode 2, message:no such file or directory, or no exit code is provided. In this situation, you must use the error log to troubleshoot the issue.The following sections describe the errors that different start commands return for non-existent files.
Incorrect file format
Function instance exited unexpectedly(code 8, message:exec format error) with start command '/code/bootstrap '. Logs:The Custom Runtime environment is an
x86-64Linux system. Ensure that the start command file is compatible with this environment. If the start command is a shell script, ensure that the file is in the Linux format and includes a shebang line (#!). If the start command is a binary executable file, ensure that it is an Executable and Linkable Format (ELF) file that is compatible with Linux.Incorrect shebang line in the start command shell script
If a shell script is missing the shebang line or the line is incorrect, the instance exit code is usually
8 exec format error. To resolve this issue, you must add the correct shebang line at the beginning of the file.To run the script using Bash, add
#!/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/shis an alias for/bin/bash. Therefore, you can also use#!/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 an extra\rcharacter afterbash. The line feed character for Unix files is\n, while the line feed character for Windows files is\r\n. This indicates that the file is in the Windows format.If you create the script on a Windows system, you must convert the file format to the Unix format. You can convert the file by running the
dos2unixcommand in a Linux system or using the Web IDE in Function Compute. For more information, see How do I use the Web IDE of Function Compute 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 a Linux-compatible ELF file. For example, on a Mac computer with an M1 chip, if you compile Go code using the default
GOOS=darwin GOARCH=arm64configuration, and then package, upload, and test the executable, the following error message is returned.Function instance exited unexpectedly(code 8, message:exec format error) with start command './main '. Logs:The instance exit code
8 exec format errorindicates an incorrect file format. You must add the configurationGOOS=linux GOARCH=amd64at compile-time. For more information, see Compile and deploy a code package.
Common exit codes
In addition to the exit codes listed above, other common errors can occur.
Exit Code 137
The program received a SIGKILL signal and exited unexpectedly. This is typically an
OOMKilled (Out of Memory)error, which occurs when a program is terminated because of insufficient memory. In this case, you can increase the memory allocated to the function.
More information
For errors not listed in this topic, see Custom Runtime FAQ.