java.io.IOException: Connection reset by peer

本文涉及的产品
云原生网关 MSE Higress,422元/月
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
注册配置 MSE Nacos/ZooKeeper,118元/月
简介: 一.场景:     spark通过phoenix 读取hbase表,其实说白了先要去Zookeeper建立connection。二.代码: 点击(此处)折叠或打开 val zkUrl = "192.
一.场景:
    spark通过phoenix 读取hbase表,其实说白了先要去Zookeeper建立connection。

二.代码:

点击(此处)折叠或打开

val zkUrl = "192.168.100.39,192.168.100.40,192.168.100.41:2181"
val formatStr = "org.apache.phoenix.spark"
val oms_orderinfoDF = spark.read.format(formatStr)
  .options(Map("table" -> "oms_orderinfo", "zkUrl" -> zkUrl))
  .load

三.查看SparkJob日志:

点击(此处)折叠或打开

17/10/24 03:25:25 INFO zookeeper.ClientCnxn: Opening socket connection to server hadoop40/192.168.100.40:2181. Will not attempt to authenticate using SASL (unknown error)
17/10/24 03:25:25 INFO zookeeper.ClientCnxn: Socket connection established, initiating session, client: /192.168.100.48:35952, server: hadoop40/192.168.100.40:2181
17/10/24 03:25:25 WARN zookeeper.ClientCnxn: Session 0x0 for server hadoop40/192.168.100.40:2181, unexpected error, closing socket connection and attempting reconnect
java.io.IOException: Connection reset by peer     at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
    at sun.nio.ch.IOUtil.read(IOUtil.java:192)
    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
    at org.apache.phoenix.shaded.org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:68)
    at org.apache.phoenix.shaded.org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:355)
    at org.apache.phoenix.shaded.org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
17/10/24 03:25:25 INFO yarn.ApplicationMaster: Deleting staging directory hdfs://nameservice1/user/hdfs/.sparkStaging/application_1507703377455_4854
17/10/24 03:25:25 INFO util.ShutdownHookManager: Shutdown hook called
主要错误是“java.io.IOException: Connection reset by peer”,其实意思很明白了 Zookeeper将connection closing.
至于为什么会被关闭connection?那么去检查一下hadoop40机器的zookeeper的日志就会发现一些有用的信息。

四.查看Zookeeper日志:

点击(此处)折叠或打开

2017-10-24 03:25:22,498 WARN org.apache.zookeeper.server.NIOServerCnxnFactory: Too many connections from /192.168.100.40 - max is 500
2017-10-24 03:25:25,588 WARN org.apache.zookeeper.server.NIOServerCnxnFactory: Too many connections from /192.168.100.40 - max is 500
2017-10-24 03:25:25,819 WARN org.apache.zookeeper.server.NIOServerCnxnFactory: Too many connections from /192.168.100.40 - max is 500
2017-10-24 03:25:26,092 WARN org.apache.zookeeper.server.NIOServerCnxn: caught end of stream exception
EndOfStreamException: Unable to read additional data from client sessionid 0x15ed091ee09897d, likely client has closed socket
    at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:231)
    at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208)
    at java.lang.Thread.run(Thread.java:745)
2017-10-24 03:25:26,092 INFO org.apache.zookeeper.server.NIOServerCnxn: Closed socket connection for client /192.168.100.40:47084 which had sessionid 0x15ed091ee09897d
2017-10-24 03:25:26,092 WARN org.apache.zookeeper.server.NIOServerCnxn: caught end of stream exception
EndOfStreamException: Unable to read additional data from client sessionid 0x15ed091ee098981, likely client has closed socket
    at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:231)
    at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208)
    at java.lang.Thread.run(Thread.java:745)
2017-10-24 03:25:26,093 INFO org.apache.zookeeper.server.NIOServerCnxn: Closed socket connection for client /192.168.100.40:47304 which had sessionid 0x15ed091ee098981
2017-10-24 03:25:26,093 WARN org.apache.zookeeper.server.NIOServerCnxn: caught end of stream exception
这个时候我们发现" Too many connections from /192.168.100.48 - max is 500 ",
那就说明这台hadoop40机器的zookeeper的当前connection数已经超过配置的500了,所以新的connection必然被closed,


五.解决方法:
那么我们只需去zookeeper的配置修改一下参数
maxClientCnxns调大到1000,重启zookeeper服务生效配置即可。

目录
相关文章
|
5月前
|
网络协议 Java 应用服务中间件
解决java.net.ConnectException: Connection refused:connect报错
解决java.net.ConnectException: Connection refused:connect报错
1174 1
|
7月前
|
Linux Windows
FinalShell连接Linux虚拟机报错java.net.ConnectException: Connection timed out: connect(亲测有效)
FinalShell连接Linux虚拟机报错java.net.ConnectException: Connection timed out: connect(亲测有效)
1317 0
|
7月前
|
SQL 分布式计算 Java
HiveOnSpark 报错:java.lang.IllegalStateException(Connection to remote Spark driver was lost)‘ Last kno
Hive On Spark 测试时遇到`java.lang.IllegalStateException`和`FileNotFoundException`,问题根源是 Spark 缺少 `hive-exec-3.1.3.jar`。解决方法:从 `$HIVE_HOME/lib/`复制该 jar 到 `$SPARK_HOME/jars/`,并使用 `hdfs dfs -put`命令将其上传至 HDFS 的 `/spark-jars/`(根据实际情况调整路径)。重启 Hive 元数据服务后问题解决。
309 0
HiveOnSpark 报错:java.lang.IllegalStateException(Connection to remote Spark driver was lost)‘ Last kno
|
7月前
|
关系型数据库 网络安全 对象存储
Flink报错问题之Flink报错java.io.EOFException: SSL peer shut down incorrectly如何解决
Flink报错通常是指在使用Apache Flink进行实时数据处理时遇到的错误和异常情况;本合集致力于收集Flink运行中的报错信息和解决策略,以便开发者及时排查和修复问题,优化Flink作业的稳定性。
|
7月前
java.lang.Exception: Apparent connection leak detected
java.lang.Exception: Apparent connection leak detected
115 0
|
7月前
java.net.ConnectException: 拒绝连接 (Connection refused) doris
java.net.ConnectException: 拒绝连接 (Connection refused) doris
404 1
|
7月前
|
分布式计算 Linux Spark
【已解决】Caused by: java.net.SocketException: Connection reset by peer: socket write error
【已解决】Caused by: java.net.SocketException: Connection reset by peer: socket write error
237 0
|
1天前
|
Java
Java—多线程实现生产消费者
本文介绍了多线程实现生产消费者模式的三个版本。Version1包含四个类:`Producer`(生产者)、`Consumer`(消费者)、`Resource`(公共资源)和`TestMain`(测试类)。通过`synchronized`和`wait/notify`机制控制线程同步,但存在多个生产者或消费者时可能出现多次生产和消费的问题。 Version2将`if`改为`while`,解决了多次生产和消费的问题,但仍可能因`notify()`随机唤醒线程而导致死锁。因此,引入了`notifyAll()`来唤醒所有等待线程,但这会带来性能问题。
Java—多线程实现生产消费者
|
3天前
|
安全 Java Kotlin
Java多线程——synchronized、volatile 保障可见性
Java多线程中,`synchronized` 和 `volatile` 关键字用于保障可见性。`synchronized` 保证原子性、可见性和有序性,通过锁机制确保线程安全;`volatile` 仅保证可见性和有序性,不保证原子性。代码示例展示了如何使用 `synchronized` 和 `volatile` 解决主线程无法感知子线程修改共享变量的问题。总结:`volatile` 确保不同线程对共享变量操作的可见性,使一个线程修改后,其他线程能立即看到最新值。
|
3天前
|
消息中间件 缓存 安全
Java多线程是什么
Java多线程简介:本文介绍了Java中常见的线程池类型,包括`newCachedThreadPool`(适用于短期异步任务)、`newFixedThreadPool`(适用于固定数量的长期任务)、`newScheduledThreadPool`(支持定时和周期性任务)以及`newSingleThreadExecutor`(保证任务顺序执行)。同时,文章还讲解了Java中的锁机制,如`synchronized`关键字、CAS操作及其实现方式,并详细描述了可重入锁`ReentrantLock`和读写锁`ReadWriteLock`的工作原理与应用场景。