{"record":{"id":"ac30bf8ec878caf1","repo":"prestodb/presto","slug":"failed-to-acquire-port-on-host","errorCode":null,"errorMessage":"Failed to acquire port on host","messagePattern":"Failed to acquire port on host","errorType":"exception","errorClass":"PrestoSparkFatalException","httpStatus":null,"severity":"critical","filePath":"presto-spark-base/src/main/java/com/facebook/presto/spark/execution/nativeprocess/AbstractNativeProcess.java","lineNumber":517,"sourceCode":"    }\n\n    public URI getLocation()\n    {\n        return location;\n    }\n\n    protected static int getAvailableTcpPort(String nodeInternalAddress)\n    {\n        try {\n            ServerSocket socket = new ServerSocket();\n            socket.bind(new InetSocketAddress(nodeInternalAddress, 0));\n            int p = socket.getLocalPort();\n            socket.close();\n            return p;\n        }\n        catch (Exception ex) {\n            // Something is wrong with the executor — fail it.\n            throw new PrestoSparkFatalException(\"Failed to acquire port on host\", ex);\n        }\n    }\n\n    private void doGetServerInfo(SettableFuture<ServerInfo> future)\n    {\n        addCallback(serverClient.getServerInfo(), new FutureCallback<BaseResponse<ServerInfo>>()\n        {\n            @Override\n            public void onSuccess(@Nullable BaseResponse<ServerInfo> response)\n            {\n                if (response.getStatusCode() != SC_OK) {\n                    throw new PrestoException(GENERIC_INTERNAL_ERROR, \"Request failed with HTTP status \" + response.getStatusCode());\n                }\n                future.set(response.getValue());\n            }\n\n            @Override\n            public void onFailure(Throwable failedReason)","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spark-base/src/main/java/com/facebook/presto/spark/execution/nativeprocess/AbstractNativeProcess.java#L499-L535","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify nodeInternalAddress resolves to a local network interface on the host (check spark/presto node address config).","Check file-descriptor limits (ulimit -n) and ephemeral port availability on the executor host; free up resources or raise limits.","Confirm the container/executor has permission to bind TCP sockets (no restrictive network policy/seccomp).","Retry the task on a different node; the failure is intentionally fatal to this executor."],"exampleFix":"// misconfigured address causes bind failure\nString addr = config.getNodeInternalAddress(); // e.g. \"10.0.0.99\" not local\nint port = getAvailableTcpPort(addr);\n// after: validate the address is local before requesting the port\nInetAddress local = InetAddress.getByName(addr);\nif (!NetworkInterface.getByInetAddress(local).isUp()) {\n    throw new ConfigurationException(\"nodeInternalAddress is not a local interface: \" + addr);\n}\nint port = getAvailableTcpPort(addr);","handlingStrategy":"validation","validationCode":"import java.net.*;\nimport java.util.*;\n\npublic static void validateCanBindPort(String nodeInternalAddress) throws Exception {\n    InetAddress addr = InetAddress.getByName(nodeInternalAddress);\n    if (NetworkInterface.getByInetAddress(addr) == null) {\n        throw new IllegalStateException(\"Address is not a local interface: \" + nodeInternalAddress);\n    }\n    try (ServerSocket s = new ServerSocket()) {\n        s.bind(new InetSocketAddress(addr, 0)); // fails fast if host can't allocate ports\n    }\n}","typeGuard":"public static boolean isBindableLocalAddress(String address) {\n    try {\n        InetAddress addr = InetAddress.getByName(address);\n        return NetworkInterface.getByInetAddress(addr) != null;\n    } catch (Exception e) {\n        return false;\n    }\n}","tryCatchPattern":null,"preventionTips":["Validate that the configured node internal address is a local, up interface before starting native processes.","Raise nofile ulimits and monitor ephemeral port usage on executor nodes.","Smoke-test port allocation in containers as part of node startup health checks.","Keep bind-address configuration (IPv4/IPv6) consistent across cluster nodes."],"tags":["network","port-allocation","presto-spark","native-execution"],"backgroundTag":"port-bind-failure","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}