All Products
Search
Document Center

Function Compute:Troubleshooting

Last Updated:Jul 11, 2023

This topic describes the common errors in custom runtimes and describes how to troubleshoot the errors.

Failed to start a function instance

Error

The function cannot be started. Failed to start function instance. Error: the file /code/bootstrap is not exist

Possible causes and troubleshooting methods

If a function instance fails to be started, the possible cause is that an exception occurred for the startup command or the startup command does not exist.

  • By default, if the startup command is not specified, Function Compute uses /code/bootstrap. If the code package does not contain the /code/bootstrap file, add a /code/bootstrap script to the code package or change the startup command.

  • If the startup command is specified, check whether the /code/bootstrap file exists.

For information about how to configure the startup command, see Create a function.

A function instance failed to pass the health check

Error

Function instance health check failed on port 9001 in 120 seconds.\nLogs:

Possible causes and troubleshooting methods

If a function instance fails to pass the health check, the possible cause is that the IP address or port that is specified for the listener in the code is incorrect. After a function instance is started, the Function Compute platform checks the connectivity of the IP port. If no result is returned for the connectivity check during the timeout period, the Function instance health check failed error is returned.

The IP address and port that is specified for the listener must meet the following requirements.

  • IP address

    Specify the IP address for the listener to 0.0.0.0 or *. We recommend that you do not set the IP address to 127.0.0.0 or localhost in the code.

  • Port

    Specify the port for the listener to be the same as the listener port that is configured in the Function Compute instance. The default listener port in a custom runtime is 9000.

    • If you use the default listener port, make sure that the port on which the HTTP server listens is 9000 in the code.

    • If you specified a listener port in the Function Compute instance, make sure that the port on which the HTTP server listens in the code is the same as the listener port that you specified.

For information about the listener port, see Create a function.

The process of a function instance exited unexpectedly

Error

Function instance exited unexpectedly(code 2, message:no such file or directory) with start command '/code/bootstrap '.
Logs:
  • Function instance exited unexpectedly indicates that the startup process of the function instance unexpectedly exited.

  • code 2, message:no such file or directory indicates the Linux exit code of the startup process and the meaning of the exit code.

  • with start command '/code/bootstrap ' shows the startup command of the function instance.

Note

The Linux exit code of a process and the meaning of the exit code are provided for reference. Identify the cause for the exited process in the error log.

Possible causes and troubleshooting methods

  • The startup command is not executable

    The function cannot be started. Function instance exited unexpectedly(code 13, message:permission denied) with start command '/code/bootstrap '.

    If the instance startup command is not executable, the exit code in the error message is code 13, message:permission denied. You can execute the chmod 755 bootstrap, chmod 777 bootstrap, or chmod +x bootstrap command to make the startup command executable before you package the code.

  • The specified 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:xxx

    If the file that you specify in the startup command does not exist, the exit code in the error message is code 2, message:no such file or directory. In some cases, the exit code in the error message may not be code 2, message:no such file or directory, or an exit code may not be included in the error message. In this case, you must troubleshoot the error based on the error log.

    The following section describes the error messages that are returned for different programming languages when the file that you specify in the startup command does not exist.

    • Python

      If the instance start command is python3 not_exist_file.py, the exit code is code 2, message:no such file or directory.

      If you paste the command in a shell script and change the startup command to /code/bootstrap, the /code/not_exist_file.py error message is returned when you execute the function. The following sample code provides an example.

      Shell script

      #!/bin/bash
      python3 not_exist_file.py

      Error message

      Function instance exited unexpectedly(code 2, message:no such file or directory) with start command '/code/bootstrap '.
      Logs:python3: can't open file '/code/not_exist_file.py': [Errno 2] No such file or directory
    • Node.js

      If the instance startup command is npm run start, and the script startup command that is specified in the package.json file is node ./not_exist_file.js, the following error message is returned.

      Function instance exited unexpectedly(code 1, message:operation not permitted) with start command 'npm run start '.
      Logs:> nodejs-express@0.0.0 start /code
      > node ./not_exist_file.js
      
      internal/modules/cjs/loader.js:905
        throw err;
        ^
      
      Error: Cannot find module '/code/not_exist_file.js'
          at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
          at Function.Module._load (internal/modules/cjs/loader.js:746:27)
          at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
          at internal/main/run_main_module.js:17:47 {
        code: 'MODULE_NOT_FOUND',
        requireStack: []
      }
      npm ERR! code ELIFECYCLE
      npm ERR! errno 1
       ERR! nodejs-express@0.0.0 start: `node ./not_exist_file.js`
       npm ERR!
       ERR! Failed at the nodejs-express@0.0.0 start script.
      npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
      
      npm ERR! A complete log of this run can be found in:
      npm ERR!     /root/.npm/_logs/2022-10-31T08_02_29_434Z-debug.log

      From the error log, you can obtain the cause Error: Cannot find module '/code/not_exist_file.js' that indicates that the /code/not_exist_file.js file does not exist. The exit code is code 1, message:operation not permitted.

      If the instance startup command is node ./not_exist_file.js, a similar error message is returned.

    • Java

      If the instance startup command is java -Dserver.port=9000 -jar target/not_exist_file.jar, the following error message is returned.

      Function instance exited unexpectedly(code 1, message:operation not permitted) with start command 'java -Dserver.port=9000 -jar target/not_exist_file.jar '.
      Logs:Error: Unable to access jarfile target/not_exist_file.jar

      From the error log, you can obtain the cause Unable to access jarfile target/not_exist_file.jar that indicates that the target/not_exist_file.jar file does not exist. The exit code is code 1, message:operation not permitted.

    • PHP

      If the instance startup command is php not_exist_file.php, the following error message is returned.

      Function instance exited unexpectedly(code 1, message:operation not permitted) with start command 'php not_exist_file.php '.
      Logs:Could not open input file: not_exist_file.php

      From the error log, you can obtain the cause Could not open input file: not_exist_file.php that indicates that the not_exist_file.php file does not exist. The exit code is code 1, message:operation not permitted.

    • .NET Core

      If the instance startup command is dotnet ./target/NotExistFile.dll, the following error message is returned.

      Function instance exited unexpectedly(code 145) with start command 'dotnet ./target/NotExistFile.dll '.
      Logs:Could not execute because the application was not found or a compatible .NET SDK is not installed.
      Possible reasons for this include:
        * You intended to execute a .NET program:
            The application './target/NotExistFile.dll' does not exist.
        * You intended to execute a .NET SDK command:
            It was not possible to find any installed .NET SDKs.
            Install a .NET SDK from:
              https://aka.ms/dotnet-download

      The returned error message contains the troubleshooting methods. The cause for the error is that the ./target/NotExistFile.dll file does not exist, or .NET SDK is not installed. The exit code is code 145.

    • Ruby

      If the instance startup command is ruby not_exist_file.rb, the following error message is returned.

      Function instance exited unexpectedly(code 1, message:operation not permitted) with start command 'ruby not_exist_file.rb '.
      Logs:Traceback (most recent call last):
      ruby: No such file or directory -- not_exist_file.rb (LoadError)

      From the error log, you can obtain the cause No such file or directory -- not_exist_file.rb that indicates that the not_exist_file.rb file does not exist. The exit code is code 1, message:operation not permitted.

  • The file is in an invalid format

    Function instance exited unexpectedly(code 8, message:exec format error) with start command '/code/bootstrap '.
    Logs:

    The custom runtime runs on a 64-bit x86 Linux system. Make sure that the startup files are supported by the system. If the startup command is a shell script, make sure that the file is in a format supported by Linux and contains the shell shebang #!. If the startup command is a binary executable file, make sure that the file is an executable and linkable format (ELF) file that is compatible with Linux operating systems. The following section describes the file format errors.

    • An error occurs in the shell shebang of the startup command

      If the shell script does not contain shebang, or the shebang content is incorrect, the instance exit code is 8 exec format error. In this case, you must add the correct shebang in the first line of the shell script.

      If you want to run the script as a bash file, add the #!/usr/bin/env bash command or #!/bin/bash command in the first line of the shell script. We recommend that you add the #!/usr/bin/env bash command. In a custom runtime environment, /bin/sh is equal to /bin/bash. You can also add the #!/usr/bin/env sh command or #!/bin/sh command in the first line of the shell script.

    • The shell script of the startup command is for Windows OSs

      Run the following test script.

      #!/usr/bin/env bash
      node /code/index.js

      The 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 directory

      In the error log, bash\r indicates that bash is followed by an additional \r. In the UNIX OS, you can end a line with \n. In the Windows OS, you can end a line with \r\n. The provided script is in a format that is designed for Windows OSs.

      If you create your script on a Windows OS, you must convert the script to a format that is compatible with UNIX OSs. You can run the dos2unix command on a Linux OS or use the WebIDE feature of Function Compute to convert your script. For more information, see How do I use the Web IDE feature of Function Compute to convert file formats?.

    • The startup command is a binary executable file that is not compatible with Linux OSs

      If the startup command is an executable file, make sure that the file is in an ELF file that is compatible with Linux OSs. For example, the following error message is returned if you use the default configuration GOOS=darwin GOARCH=arm64 to compile the Golang code and test the packaged code on a Mac computer that runs on the M1 chip.

      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 is in an invalid format. You must add the GOOS=linux GOARCH=amd64 configuration when you compile the code. For more information, see Compilation and deployment of code packages.

      Check the format of executable files in the code

      • The following sample code provides an example on how to check the format of an executable file that is compiled by using the GOOS=darwin GOARCH=arm64 configuration.

        $ file main
        main: Mach-O 64-bit arm64 executable, flags:<|DYLDLINK|PIE>

        The file format is Mach-O. The CPU architecture is arm64. The executable file is incompatible with the OS.

      • The following sample code provides an example on how to check the format of an executable file that is compiled by using the GOOS=linux GOARCH=amd64 configuration.

        $ file main
        main: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=xxx, not stripped

        The file format is ELF. The CPU architecture is x86-64. The executable file is compatible with OS.

      Note
      • Typically, executable files are in the ELF format in Linux OSs.

      • Executable files are in the Mach-O format in Mac OSs.

      • Executable files are in the portable executable (PE) format in Windows OSs.

  • Common exit codes

    The following section describes other common exit codes.

    • Exit Code 137

      In most cases, this exit code is returned due to the OOMKilled(Out of Memory) error that indicates that the memory is insufficient. 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 the Custom Runtime FAQ.