Error handling

更新时间:
复制 MD 格式

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/bootstrap as the default start command. If this file is not in your code package, you can add the /code/bootstrap script or modify the Startup Command.

  • If you set the Startup Command, check the error message Error: the file xxx is not exist to 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.0 or *. It cannot be set to 127.0.0.0 or localhost.

  • 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 unexpectedly indicates that the instance startup process exited unexpectedly.

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

  • with start command '/code/bootstrap ' indicates the start command of the instance.

Note

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 run chmod 755 bootstrap, chmod 777 bootstrap, or chmod +x bootstrap to 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:xxx

    If 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 from code 2, message:no such file or directory or may be absent. If so, troubleshoot based on the error log.

    The following sections show error messages for missing files with different start commands.

    • Python

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

      If you put this start command in a shell script, as shown in the following example, and then change the start command to /code/bootstrap, an error is reported indicating that /code/not_exist_file.py does not exist when you execute the function.

      Shell script example

      #!/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

      When the instance start command is npm run start and the script start command configured in package.json is node ./not_exist_file.js, the following error message is reported.

      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

      The cause can be found in the error log: Error: Cannot find module '/code/not_exist_file.js'. This means that /code/not_exist_file.js does not exist. The exit code is code 1, message:operation not permitted.

      A similar error occurs when the instance start command is node ./not_exist_file.js.

    • Java

      When the instance start command is java -Dserver.port=9000 -jar target/not_exist_file.jar, the following error message is reported.

      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

      The cause can be found in the error log: Unable to access jarfile target/not_exist_file.jar. This means that the target/not_exist_file.jar file does not exist. The exit code is code 1, message:operation not permitted.

    • PHP

      When the instance start command is php not_exist_file.php, the following error message is reported.

      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

      The cause can be found in the error log: Could not open input file: not_exist_file.php. This means that the not_exist_file.php file does not exist. The exit code is code 1, message:operation not permitted.

    • .NET Core

      When the instance start command is dotnet ./target/NotExistFile.dll, the following error message is reported.

      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 the following:
        * 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 error log provides detailed troubleshooting methods. The ./target/NotExistFile.dll file does not exist or the .NET SDK is not installed. The exit code is code 145.

    • Ruby

      When the instance start command is ruby not_exist_file.rb, the following error message is reported.

      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)

      The cause can be found in the error log: No such file or directory -- not_exist_file.rb. This means that the not_exist_file.rb file does not exist. The exit code is code 1, message:operation not permitted.

  • 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-64 architecture. 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 bash or #!/bin/bash to the first line of the file. We recommend that you use #!/usr/bin/env bash. In the custom runtime environment, /bin/sh defaults to /bin/bash. Therefore, you can also use the command #!/usr/bin/env sh or #!/bin/sh.

    • The start command shell script is in Windows format

      Run the following test script.

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

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

      In the error log, bash\r indicates that there is an extra \r character after bash. 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 dos2unix command 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 the GOOS=linux GOARCH=amd64 configuration at compile-time. For more information, see Compile and deploy a code package.

      Click to view how to determine the format of an executable file.

      • You can view the format of the executable file compiled with GOOS=darwin GOARCH=arm64, as shown below.

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

        Its file format is Mach-O and the CPU architecture is arm64, which is not compatible with the underlying environment of the custom runtime.

      • You can view the format of the executable file compiled with GOOS=linux GOARCH=amd64, as shown below.

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

        Its file format is ELF and the CPU architecture is x86-64, which is compatible with the underlying environment of the custom runtime.

      Note
      • The executable file format for Linux systems is usually ELF.

      • The executable file format for Mac systems is Mach-O.

      • The executable file format for Windows systems is PE.

  • 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.