In a custom runtime, your code package (ZIP format) is an HTTP server program. Function Compute starts that HTTP server during a cold start and routes all incoming requests through it.
How it works
When Function Compute performs a cold start, it runs the Startup Command and Startup Parameter you configured to launch your HTTP server. The HTTP server then takes over all requests from Function Compute.
If you do not configure a startup command or parameters, Function Compute starts the HTTP server from /code/bootstrap by default.
The cold start completes in two stages:
Platform preparation — Function Compute initializes the execution environment and prepares to launch your code.
HTTP server startup — Function Compute runs your startup command. The HTTP server must be ready within 120 seconds.
Configure the startup command
The startup command is defined in customRuntimeConfig:
| Field | Description |
|---|---|
command | The executable to run |
args | Arguments passed to the executable |
Function Compute concatenates command and args to form the complete startup command.
Suppose your code package is named function.zip. The following examples show the package structure and the corresponding customRuntimeConfig for each runtime.
Java 8 or Spring Boot
.
└── demo.jarcustomRuntimeConfig:
command:
- java
args:
- '-jar'
- 'demo.jar'Python 3.7
.
└── server.pycustomRuntimeConfig:
command:
- python
args:
- 'server.py'Node.js 10
.
└── server.jscustomRuntimeConfig:
command:
- node
args:
- 'server.js'PHP 7.4
.
└── server.phpcustomRuntimeConfig:
command:
- php
args:
- 'server.php'HTTP server requirements
Configure your HTTP server to meet the following requirements. Violating any of these causes Function Compute to reject or fail the connection.
| Requirement | Details | Error if violated |
|---|---|---|
| Bind to the correct address | Listen on 0.0.0.0:CAPort or *:CAPort. Do not use 127.0.0.1:CAPort. | FunctionNotStarted — connection refused |
| Match the configured port | The server's listening port must match the CAPort value in your function configurations. The default is 9000. To use a different port (for example, 8080), set CAPort to 8080 in your function configurations. | FunctionNotStarted — ping failed |
| Enable keep-alive | Enable keep-alive mode and set the connection timeout to at least 24 hours (the maximum function execution duration). | Connections drop mid-execution |
| Start within 120 seconds | The HTTP server must be ready to accept connections within 120 seconds of launch. | Startup fails |
Example: keep-alive configuration (Node.js with Express)
const server = app.listen(PORT, HOST);
server.timeout = 0; // never timeout
server.keepAliveTimeout = 0; // keep-alive, never timeoutError reference: binding to 127.0.0.1
If the HTTP server listens on 127.0.0.1 instead of 0.0.0.0, Function Compute cannot reach it and returns:
{
"ErrorCode": "FunctionNotStarted",
"ErrorMessage": "TheCA'shttpservercannotbestarted:ContainerStartDuration:25000000000.PingCAfaileddueto:dialtcp21.0.XX.XX:9000:getsockopt:connectionrefusedLogs:2019-11-29T09:53:30.859837462ZListeningonport9000"
}