fix timer thread hang inner 1790 & 2037 (#3287)

fix timer thread  hang inner 1790 & 2037 (#3287)
This commit is contained in:
ylinzhu
2023-02-08 17:19:03 +08:00
committed by GitHub
3 changed files with 21 additions and 14 deletions

View File

@@ -1,8 +1,8 @@
/*
* Copyright (C) 2016-2019 ActionTech.
* based on code by MyCATCopyrightHolder Copyright (c) 2013, OpenCloudDB/MyCAT.
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
*/
* Copyright (C) 2016-2019 ActionTech.
* based on code by MyCATCopyrightHolder Copyright (c) 2013, OpenCloudDB/MyCAT.
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
*/
package com.actiontech.dble.backend.mysql.nio.handler;
import com.actiontech.dble.backend.BackendConnection;
@@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
@@ -22,11 +23,17 @@ public class NewConnectionRespHandler implements ResponseHandler {
private ReentrantLock lock = new ReentrantLock();
private Condition initiated = lock.newCondition();
private String errMsg;
public BackendConnection getBackConn() throws IOException {
lock.lock();
boolean await = true;
try {
if (backConn == null) {
initiated.await();
if (errMsg == null && backConn == null) {
await = initiated.await(10000, TimeUnit.MILLISECONDS);
}
if (!await) {
errMsg = "test conn timeout,TCP connection may be lost";
LOGGER.warn(errMsg);
}
if (backConn == null) {
throw new IOException(errMsg);
@@ -104,7 +111,14 @@ public class NewConnectionRespHandler implements ResponseHandler {
@Override
public void connectionClose(BackendConnection conn, String reason) {
lock.lock();
try {
errMsg = "Backend connect connectionClose, Connection{DataHost[" + conn.getHost() + ":" + conn.getPort() + "],Schema[" + conn.getSchema() + "]}";
initiated.signal();
} finally {
lock.unlock();
}
LOGGER.info("connectionClose " + conn);
}

View File

@@ -282,7 +282,6 @@ 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");
}

View File

@@ -123,16 +123,10 @@ 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;
}
}