首页 Function Compute Function Compute FAQ Function management FAQ about function debugging Fix "Process exited unexpectedly before completing request"

Fix "Process exited unexpectedly before completing request"

更新时间: 2026-06-23 14:25:25

The function process terminated before completing a request, typically due to incorrect function logic or missing HTTP server keep-alive configuration.

Incorrect function logic

A bug in function code can cause the process to exit prematurely, often involving downstream database operations. In the following Python example, os._exit(-1) terminates the process before the function returns a response:

# -*- coding: utf-8 -*-
import os
import logging

def handler(event, context):
    logger = logging.getLogger()
    logger.info('hello world')
    os._exit(-1)  # Terminates the process immediately
    return 'hello world'

Add logging with logging.getLogger() and check the function logs. Look for unhandled exceptions and explicit exit calls such as os._exit().

Missing keep-alive in custom runtimes

When you use a custom runtime or Custom Container runtime with a function execution timeout under 15 minutes, the HTTP server must have keep-alive enabled. Otherwise, the server may close idle connections and cause the process to exit unexpectedly.

Enable keep-alive and set the request timeout to 24 hours or longer. The following Node.js example shows the required configuration:

const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200);
  res.end('OK');
});

server.timeout = 0;
server.keepAliveTimeout = 0;

server.listen(9000, '0.0.0.0');

Ensure the HTTP server meets these requirements:

  • Listens on 0.0.0.0:CAPort or *:CAPort, not 127.0.0.1. The default port is 9000.

  • Starts within 120 seconds.

For the full list of HTTP server requirements, see Requirements on HTTP server configurations.

上一篇: How do I view the public IP address of Function Compute? 下一篇: What is a VPC?
阿里云首页 函数计算 相关技术圈