diff --git a/internal/event/target/mqtt.go b/internal/event/target/mqtt.go index 171486e25..aa2a2475e 100644 --- a/internal/event/target/mqtt.go +++ b/internal/event/target/mqtt.go @@ -219,7 +219,9 @@ func (target *MQTTTarget) Save(eventData event.Event) error { // Close - does nothing and available for interface compatibility. func (target *MQTTTarget) Close() error { - target.client.Disconnect(100) + if target.client != nil { + target.client.Disconnect(100) + } close(target.quitCh) return nil } diff --git a/internal/event/target/mysql.go b/internal/event/target/mysql.go index bc6c53c84..48966f4b9 100644 --- a/internal/event/target/mysql.go +++ b/internal/event/target/mysql.go @@ -312,7 +312,11 @@ func (target *MySQLTarget) Close() error { _ = target.insertStmt.Close() } - return target.db.Close() + if target.db != nil { + return target.db.Close() + } + + return nil } // Executes the table creation statements. diff --git a/internal/event/target/postgresql.go b/internal/event/target/postgresql.go index 132b6d40c..736bafe33 100644 --- a/internal/event/target/postgresql.go +++ b/internal/event/target/postgresql.go @@ -308,7 +308,11 @@ func (target *PostgreSQLTarget) Close() error { _ = target.insertStmt.Close() } - return target.db.Close() + if target.db != nil { + target.db.Close() + } + + return nil } // Executes the table creation statements. diff --git a/internal/event/target/redis.go b/internal/event/target/redis.go index ad8d2a917..cc483404c 100644 --- a/internal/event/target/redis.go +++ b/internal/event/target/redis.go @@ -273,7 +273,10 @@ func (target *RedisTarget) SendFromStore(eventKey string) error { // Close - releases the resources used by the pool. func (target *RedisTarget) Close() error { close(target.quitCh) - return target.pool.Close() + if target.pool != nil { + return target.pool.Close() + } + return nil } func (target *RedisTarget) init() error {