From 42820bfdcb915ef962cf9011ae710b3ecdb1f46d Mon Sep 17 00:00:00 2001 From: MrLeea <64508229+leepala@users.noreply.github.com> Date: Fri, 22 Sep 2023 09:33:05 +0800 Subject: [PATCH] close db when insert finished (#714) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * close db when insert finished * use defer instead of return db.close --------- Co-authored-by: 李毓琪 --- pkg/telemetryservice/sql/mysql/mysql.go | 2 ++ pkg/telemetryservice/sql/sqlserver/sqlserver.go | 2 ++ pkg/telemetryservice/sql/tdengine/tdengine.go | 2 ++ 3 files changed, 6 insertions(+) diff --git a/pkg/telemetryservice/sql/mysql/mysql.go b/pkg/telemetryservice/sql/mysql/mysql.go index 0f4b47f50..cbdefacd0 100644 --- a/pkg/telemetryservice/sql/mysql/mysql.go +++ b/pkg/telemetryservice/sql/mysql/mysql.go @@ -35,6 +35,8 @@ func (db *DBHelper) SendToDB(ctx context.Context, deviceName string, rawData []b return err } + defer db.DB.Close() + err = db.InsertDataToDB(ctx, deviceName, rawData) if err != nil { logger.Errorf("Error to Insert rawData to DB, errror: %v", err.Error()) diff --git a/pkg/telemetryservice/sql/sqlserver/sqlserver.go b/pkg/telemetryservice/sql/sqlserver/sqlserver.go index c661798b8..2f2f4e791 100644 --- a/pkg/telemetryservice/sql/sqlserver/sqlserver.go +++ b/pkg/telemetryservice/sql/sqlserver/sqlserver.go @@ -35,6 +35,8 @@ func (db *DBHelper) SendToDB(ctx context.Context, deviceName string, rawData []b return err } + defer db.DB.Close() + err = db.InsertDataToDB(ctx, deviceName, rawData) if err != nil { logger.Errorf("Error to Insert rawData to DB, errror: %v", err.Error()) diff --git a/pkg/telemetryservice/sql/tdengine/tdengine.go b/pkg/telemetryservice/sql/tdengine/tdengine.go index 70acfc4c4..e603f0b20 100644 --- a/pkg/telemetryservice/sql/tdengine/tdengine.go +++ b/pkg/telemetryservice/sql/tdengine/tdengine.go @@ -28,6 +28,8 @@ func (db *DBHelper) SendToDB(ctx context.Context, deviceName string, rawData []b return err } + defer db.DB.Close() + err = db.InsertDataToDB(ctx, deviceName, rawData) if err != nil { logger.Errorf("Error to Insert rawData to DB, errror: %v", err.Error())