使用Presto CLI执行查询时遇java.net.SocketTimeoutException问题求助
问题描述
当我通过Presto CLI执行查询show schemas from hive.default;时,遇到了Socket超时和连接关闭的错误,完整错误日志如下:
[hadoop@ip-172-16-125-74 ~]$ presto-cli --debug presto> show schemas from hive.default; Error running command: java.net.SocketTimeoutException: timeout java.io.UncheckedIOException: java.net.SocketTimeoutException: timeout at com.facebook.presto.client.JsonResponse.execute(JsonResponse.java:148) at com.facebook.presto.client.StatementClient.<init>(StatementClient.java:118) at com.facebook.presto.cli.QueryRunner.startInternalQuery(QueryRunner.java:102) at com.facebook.presto.cli.QueryRunner.startQuery(QueryRunner.java:97) at com.facebook.presto.cli.Console.process(Console.java:336) at com.facebook.presto.cli.Console.runConsole(Console.java:262) at com.facebook.presto.cli.Console.run(Console.java:148) at com.facebook.presto.cli.Presto.main(Presto.java:32) Caused by: java.net.SocketTimeoutException: timeout at okio.Okio$4.newTimeoutException(Okio.java:230) at okio.AsyncTimeout.exit(AsyncTimeout.java:285) at okio.AsyncTimeout$2.read(AsyncTimeout.java:241) at okio.RealBufferedSource.indexOf(RealBufferedSource.java:345) at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:217) at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:211) at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189) at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:75) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185) at okhttp3.RealCall.execute(RealCall.java:69) at com.facebook.presto.client.JsonResponse.execute(JsonResponse.java:130) ... 7 more Caused by: java.net.SocketException: Socket closed at java.net.SocketInputStream.read(SocketInputStream.java:204) at java.net.SocketInputStream.read(SocketInputStream.java:141) at okio.Okio$2.read(Okio.java:139) at okio.AsyncTimeout$2.read(AsyncTimeout.java:237) ... 27 more
解决方案
针对这个问题,我们可以从以下几个方向逐步排查:
1. 验证Presto Coordinator服务状态
首先确认你的Presto Coordinator是否正常运行:
- 执行以下命令检查服务可用性:
如果返回包含版本、环境信息的JSON,说明服务正常;如果连接失败,需要重启Presto服务并查看日志(默认日志路径为curl http://<your-presto-coordinator-ip>:8080/v1/info/var/log/presto/)排查启动故障。
2. 检查网络连通性
这个错误很大概率是客户端和Coordinator之间的网络问题:
- 在客户端机器上ping Coordinator的IP,确认网络可达;
- 用
telnet或nc测试端口是否开放(默认8080):telnet <presto-coordinator-ip> 8080 # 或者 nc -zv <presto-coordinator-ip> 8080 - 如果是云服务器,检查安全组、防火墙规则是否允许客户端IP访问Coordinator的8080端口。
3. 调整Presto CLI超时参数
默认的超时时间可能不足以完成查询,你可以在启动CLI时增加超时配置:
presto-cli --debug --client-request-timeout 30s --server <presto-coordinator-ip>:8080
如果需要长期生效,可以修改Presto配置文件中的http-client.request-timeout参数(通常在etc/config.properties)。
4. 检查Hive Connector配置与状态
因为你查询的是Hive的schema,需要确认Hive Connector是否正常工作:
- 检查
etc/catalog/hive.properties中的配置,确保Hive Metastore的地址、端口配置正确; - 先在Presto CLI中执行
show catalogs;,确认hivecatalog存在; - 尝试简化查询语句,比如用
show schemas in hive;替代show schemas from hive.default;,排除语法层面的潜在问题。
内容的提问来源于stack exchange,提问作者nnc
相关产品推荐
相关产品推荐

