prestodb/presto · critical · PrestoSparkFatalException

Failed to acquire port on host

Error message

Failed to acquire port on host

What it means

AbstractNativeProcess.getAvailableTcpPort opens a ServerSocket bound to port 0 on the node's internal address to let the OS pick a free ephemeral port for a native worker process. If bind or close throws (any Exception), it wraps it in PrestoSparkFatalException, deliberately failing the Spark executor/task fatally because the host cannot even allocate a port, so native execution cannot proceed.

Source

Thrown at presto-spark-base/src/main/java/com/facebook/presto/spark/execution/nativeprocess/AbstractNativeProcess.java:517

    }

    public URI getLocation()
    {
        return location;
    }

    protected static int getAvailableTcpPort(String nodeInternalAddress)
    {
        try {
            ServerSocket socket = new ServerSocket();
            socket.bind(new InetSocketAddress(nodeInternalAddress, 0));
            int p = socket.getLocalPort();
            socket.close();
            return p;
        }
        catch (Exception ex) {
            // Something is wrong with the executor — fail it.
            throw new PrestoSparkFatalException("Failed to acquire port on host", ex);
        }
    }

    private void doGetServerInfo(SettableFuture<ServerInfo> future)
    {
        addCallback(serverClient.getServerInfo(), new FutureCallback<BaseResponse<ServerInfo>>()
        {
            @Override
            public void onSuccess(@Nullable BaseResponse<ServerInfo> response)
            {
                if (response.getStatusCode() != SC_OK) {
                    throw new PrestoException(GENERIC_INTERNAL_ERROR, "Request failed with HTTP status " + response.getStatusCode());
                }
                future.set(response.getValue());
            }

            @Override
            public void onFailure(Throwable failedReason)

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Verify nodeInternalAddress resolves to a local network interface on the host (check spark/presto node address config).
  2. Check file-descriptor limits (ulimit -n) and ephemeral port availability on the executor host; free up resources or raise limits.
  3. Confirm the container/executor has permission to bind TCP sockets (no restrictive network policy/seccomp).
  4. Retry the task on a different node; the failure is intentionally fatal to this executor.

Example fix

// misconfigured address causes bind failure
String addr = config.getNodeInternalAddress(); // e.g. "10.0.0.99" not local
int port = getAvailableTcpPort(addr);
// after: validate the address is local before requesting the port
InetAddress local = InetAddress.getByName(addr);
if (!NetworkInterface.getByInetAddress(local).isUp()) {
    throw new ConfigurationException("nodeInternalAddress is not a local interface: " + addr);
}
int port = getAvailableTcpPort(addr);
Defensive patterns

Strategy: validation

Validate before calling

import java.net.*;
import java.util.*;

public static void validateCanBindPort(String nodeInternalAddress) throws Exception {
    InetAddress addr = InetAddress.getByName(nodeInternalAddress);
    if (NetworkInterface.getByInetAddress(addr) == null) {
        throw new IllegalStateException("Address is not a local interface: " + nodeInternalAddress);
    }
    try (ServerSocket s = new ServerSocket()) {
        s.bind(new InetSocketAddress(addr, 0)); // fails fast if host can't allocate ports
    }
}

Type guard

public static boolean isBindableLocalAddress(String address) {
    try {
        InetAddress addr = InetAddress.getByName(address);
        return NetworkInterface.getByInetAddress(addr) != null;
    } catch (Exception e) {
        return false;
    }
}

Prevention

When it happens

Trigger: Calling getAvailableTcpPort(nodeInternalAddress) when the bind to (nodeInternalAddress, 0) throws a SocketException/BindException — e.g. the node internal address is not a local interface, the network stack is exhausted, or the process lacks permission to bind sockets.

Common situations: Misconfigured presto-spark node internal address (hostname not resolvable to a local NIC); file-descriptor or ephemeral-port exhaustion on busy containers; containers running without network privileges; IPv6/IPv4 address mismatch for the bind address.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/ac30bf8ec878caf1. Report an issue: GitHub.