fix heartbeat deadlock inner 1372 (#2867)

# Conflicts:
#	src/main/java/com/actiontech/dble/net/NIOSocketWR.java
This commit is contained in:
ylinzhu
2021-09-16 17:04:38 +08:00
committed by lin
parent 46d316009d
commit 2f5e5599a2
5 changed files with 24 additions and 0 deletions
@@ -43,6 +43,10 @@ public class MySQLConnectionAuthenticator implements NIOHandler {
listener.connectionError(e, c);
}
}
// only for test
public ResponseHandler getListener() {
return listener;
}
@Override
public void handle(byte[] data) {
@@ -128,4 +128,9 @@ public final class ClusterDelayProvider {
}
//only for test need delete
public static void heartbeat() {
}
}
@@ -285,6 +285,7 @@ public abstract class AbstractConnection implements NIOConnection {
if (got < 0) {
if (this instanceof MySQLConnection) {
((MySQLConnection) this).closeInner("stream closed");
((MySQLConnection) this).onConnectFailed(new IOException("stream closed"));
} else {
this.close("stream closed");
}
@@ -123,10 +123,16 @@ public final class NIOReactor {
con.asyncRead();
} catch (IOException e) {
con.close("program err:" + e.toString());
if (con instanceof MySQLConnection) {
((MySQLConnection) con).onConnectFailed(e);
}
continue;
} catch (Exception e) {
LOGGER.warn("caught err:", e);
con.close("program err:" + e.toString());
if (con instanceof MySQLConnection) {
((MySQLConnection) con).onConnectFailed(e);
}
continue;
}
}
@@ -6,6 +6,9 @@
package com.actiontech.dble.net;
import com.actiontech.dble.backend.mysql.nio.MySQLConnection;
import com.actiontech.dble.backend.mysql.nio.MySQLConnectionAuthenticator;
import com.actiontech.dble.backend.mysql.nio.handler.NewConnectionRespHandler;
import com.actiontech.dble.btrace.provider.ClusterDelayProvider;
import com.actiontech.dble.util.TimeUtil;
import java.io.IOException;
@@ -242,6 +245,11 @@ public class NIOSocketWR extends SocketWR {
@Override
public void asyncRead() throws IOException {
// only for test
if (con.getHandler() instanceof MySQLConnectionAuthenticator && ((MySQLConnectionAuthenticator) con.getHandler()).getListener() instanceof NewConnectionRespHandler) {
ClusterDelayProvider.heartbeat();
}
ByteBuffer theBuffer = con.readBuffer;
if (theBuffer == null) {
theBuffer = con.processor.getBufferPool().allocate(con.processor.getBufferPool().getChunkSize());