① 集群某实例宕掉时,如果连接刚好不处于通信阶段,tcp连接正处于CLOSE_WAIT状态或已关闭,当应用通过连接池getConnection时,在borrow时会检测连接,由于连接已关闭,于是报了如下报错,并重新建立新连接,此时的新连接到集群的其他实例上了。后面能正常通信。
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3143) at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:597) ... 21 more② 集群某实例宕掉时,如果连接刚好处于通信阶段,由于客户端无法立即感知服务端已断连接,它可能会报如下错误,等待服务端的响应超时报错。当应用通过连接池getConnection时,在borrow时会检测连接,由于连接已关闭,于是报了如下报错,并重新建立新连接,此时的新连接到集群的其他实例上了。后面能正常通信。
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 10,538 milliseconds ago. The last packet sent successfully to the server was 10,306 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure========广告时间========
鄙人的新书《Tomcat内核设计剖析》已经在京东销售了,有需要的朋友可以到 https://item.jd.com/12185360.html 进行预定。感谢各位朋友。
为什么写《Tomcat内核设计剖析》
=========================
欢迎关注:
超人汪小建(seaboat) 认证博客专家 seaboat 公众号:【远洋号】,笔名seaboat,擅长工程算法、人工智能算法、自然语言处理、计算机视觉、架构、分布式、高并发、大数据和搜索引擎等方面的技术,大多数编程语言都会使用,但更擅长Java、Python和C++。平时喜欢编程、绘画、看书、写作和运动,擅长素描、篮球、跑步、游泳、健身和羽毛球等运动项目。崇尚技术自由,崇尚思想自由。出版书籍:《Tomcat内核设计剖析》、《图解数据结构与算法》、《图解Java并发原理》、《人工智能原理科普》。