mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-25 02:00:09 +08:00
🐛 fix(ssh): 为共享端口转发增加引用计数与失败回滚
This commit is contained in:
@@ -56,13 +56,20 @@ func (t *TDengineDB) getDSN(config connection.ConnectionConfig) string {
|
||||
return dsn + "?" + query
|
||||
}
|
||||
|
||||
func (t *TDengineDB) Connect(config connection.ConnectionConfig) error {
|
||||
func (t *TDengineDB) Connect(config connection.ConnectionConfig) (err error) {
|
||||
_ = t.Close()
|
||||
defer func() {
|
||||
if err != nil {
|
||||
_ = t.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
runConfig := config
|
||||
|
||||
if config.UseSSH {
|
||||
logger.Infof("TDengine 使用 SSH 连接:地址=%s:%d 用户=%s", config.Host, config.Port, config.User)
|
||||
|
||||
forwarder, err := ssh.GetOrCreateLocalForwarder(config.SSH, config.Host, config.Port)
|
||||
forwarder, err := ssh.AcquireLocalForwarder(config.SSH, config.Host, config.Port)
|
||||
if err != nil {
|
||||
return fmt.Errorf("创建 SSH 隧道失败:%w", err)
|
||||
}
|
||||
@@ -118,7 +125,7 @@ func (t *TDengineDB) Connect(config connection.ConnectionConfig) error {
|
||||
|
||||
func (t *TDengineDB) Close() error {
|
||||
if t.forwarder != nil {
|
||||
if err := t.forwarder.Close(); err != nil {
|
||||
if err := t.forwarder.Release(); err != nil {
|
||||
logger.Warnf("关闭 TDengine SSH 端口转发失败:%v", err)
|
||||
}
|
||||
t.forwarder = nil
|
||||
|
||||
Reference in New Issue
Block a user