fix: a possible crash in event target Close() (#17948)

these are possible crashes when the configured
target is still in init() state and never finished
- however a delete config was initiated.
This commit is contained in:
Harshavardhana 2023-08-30 07:27:45 -07:00 committed by GitHub
parent b48bbe08b2
commit 0d1fbef751
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 4 deletions

View File

@ -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 {
if target.client != nil {
target.client.Disconnect(100)
}
close(target.quitCh)
return nil
}

View File

@ -312,9 +312,13 @@ func (target *MySQLTarget) Close() error {
_ = target.insertStmt.Close()
}
if target.db != nil {
return target.db.Close()
}
return nil
}
// Executes the table creation statements.
func (target *MySQLTarget) executeStmts() error {
_, err := target.db.Exec(fmt.Sprintf(mysqlTableExists, target.args.Table))

View File

@ -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.

View File

@ -273,8 +273,11 @@ func (target *RedisTarget) SendFromStore(eventKey string) error {
// Close - releases the resources used by the pool.
func (target *RedisTarget) Close() error {
close(target.quitCh)
if target.pool != nil {
return target.pool.Close()
}
return nil
}
func (target *RedisTarget) init() error {
return target.initOnce.Do(target.initRedis)