{"record":{"id":"a15efafa71020620","repo":"prestodb/presto","slug":"failed-connecting-to-hive-metastore-addresses","errorCode":null,"errorMessage":"Failed connecting to Hive metastore: ${addresses}","messagePattern":"Failed connecting to Hive metastore: (.+?)","errorType":"exception","errorClass":"TException","httpStatus":null,"severity":"critical","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/StaticHiveCluster.java","lineNumber":89,"sourceCode":"        if (metastoreLoadBalancingEnabled) {\n            Collections.shuffle(metastores);\n        }\n\n        TException lastException = null;\n        for (HostAndPort metastore : metastores) {\n            try {\n                HiveMetastoreClient client = clientFactory.create(metastore, token);\n\n                if (!isNullOrEmpty(metastoreUsername)) {\n                    client.setUGI(metastoreUsername);\n                }\n                return client;\n            }\n            catch (TException e) {\n                lastException = e;\n            }\n        }\n        throw new TException(\"Failed connecting to Hive metastore: \" + addresses, lastException);\n    }\n\n    private static URI checkMetastoreUri(URI uri)\n    {\n        requireNonNull(uri, \"metastoreUri is null\");\n        String scheme = uri.getScheme();\n        checkArgument(!isNullOrEmpty(scheme), \"metastoreUri scheme is missing: %s\", uri);\n        checkArgument(scheme.equals(\"thrift\"), \"metastoreUri scheme must be thrift: %s\", uri);\n        checkArgument(uri.getHost() != null, \"metastoreUri host is missing: %s\", uri);\n        checkArgument(uri.getPort() != -1, \"metastoreUri port is missing: %s\", uri);\n        return uri;\n    }\n}\n","sourceCodeStart":71,"sourceCodeEnd":103,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/StaticHiveCluster.java#L71-L103","documentation":"StaticHiveCluster.createMetastoreClient loops over every configured metastore URI and attempts a Thrift connection; if all attempts fail with a TException, it throws this aggregate TException with the list of addresses and the last underlying exception as its cause. It means Presto could not open a working Thrift session to any Hive metastore host in the static cluster.","triggerScenarios":"Any Presto query or catalog operation requiring metastore access when none of the URIs in hive.metastore (or the hive.metastore.thrift.uris list) accept a connection: connection refused, TLS handshake failure, auth failure, or timeout on each host.","commonSituations":"Metastore service down or never started; wrong hive.metastore.thrift.uris port (default 9083); firewall/security-group blocking; kerberos or SSL misconfiguration on the client; metastore host DNS not resolving inside containers; metastore overloaded and dropping connections.","solutions":["Verify the metastore is up and listening: run `nc -vz <host> 9083` from the Presto coordinator and start hive-metastore service if down","Check hive.metastore.thrift.uris values for typos in host/port/scheme; confirm the port matches hive.metastore.uris on the metastore side","Inspect the `cause` (lastException) of this exception in the coordinator log — it holds the real per-host failure (refused, timeout, SSL, SASL)","Open firewall/security groups for the metastore port and confirm DNS resolves the configured hostnames","If metastore is healthy but slow, raise hive.metastore.thrift.client.connect-timeout / read-timeout and metastore refresh settings"],"exampleFix":"// before\nhive.metastore=thrift\nhive.metastore.thrift.uris=thrift://meta-internal:9083\n// after\nhive.metastore=thrift\nhive.metastore.thrift.uris=thrift://metastore-host.example.com:9083\n# verified with: nc -vz metastore-host.example.com 9083","handlingStrategy":"try-catch","validationCode":"// Pre-flight: verify at least one metastore URI is reachable before initializing the catalog\nList<String> uris = Arrays.asList(\"thrift://metastore-host.example.com:9083\");\nfor (String uri : uris) {\n    try {\n        URI u = new URI(uri);\n        try (Socket s = new Socket()) {\n            s.connect(new InetSocketAddress(u.getHost(), u.getPort()), 3000); // fails fast if refused\n        }\n    } catch (Exception e) {\n        throw new IllegalStateException(\"Metastore unreachable: \" + uri, e);\n    }\n}","typeGuard":"public static boolean isConnectionFailure(Throwable t) {\n    Throwable root = t;\n    while (root.getCause() != null) root = root.getCause();\n    return root instanceof ConnectException || root instanceof UnknownHostException\n        || root instanceof SocketTimeoutException || root instanceof TTransportException;\n}","tryCatchPattern":"try {\n    HiveMetastoreClient client = staticHiveCluster.createMetastoreClient(metastoreContext);\n} catch (TException e) {\n    if (isConnectionFailure(e)) {\n        log.error(\"No metastore host reachable; cause={}\", rootCause(e).getMessage(), e);\n        throw new RetriableException(\"Metastore cluster unreachable: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Configure multiple metastore URIs for redundancy and keep them in sync with service discovery","Run nc -vz host 9083 health checks in monitoring for every configured metastore host","Match connect/read timeouts to metastore latency SLOs","Verify DNS and firewall rules from Presto nodes during environment provisioning"],"tags":["network","thrift","hive-metastore","connection","configuration"],"backgroundTag":"connection-refused","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"}