Skip to content

Commit f28f91c

Browse files
fix(database_observability.mysql): Ensure result sets are properly closed (#5893)
### Brief description of Pull Request Fixes: - In `schema_details`, moved the `defer rs.Close()` statement to after the loop, to ensure result set is closed at the end of its loop rather than holding connections open until the function returns. - In `setup_consumers`, added missing error check on result set after iteration. ### Pull Request Details <!-- Detailed descripion of the Pull Request, if needed. --> ### Issue(s) fixed by this Pull Request <!-- Fixes #issue_id --> ### Notes to the Reviewer <!-- Relevant notes for reviewers/testers. --> ### PR Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [ ] Documentation added - [ ] Tests updated - [ ] Config converters updated
1 parent 9dc2e83 commit f28f91c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

internal/component/database_observability/mysql/collector/schema_details.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ func (c *SchemaDetails) extractSchema(ctx context.Context) error {
272272
level.Error(c.logger).Log("msg", "failed to query tables", "err", err)
273273
break
274274
}
275-
defer rs.Close()
276275

277276
for rs.Next() {
278277
var tableName, tableType string
@@ -298,8 +297,11 @@ func (c *SchemaDetails) extractSchema(ctx context.Context) error {
298297
)
299298
}
300299

301-
if err := rs.Err(); err != nil {
302-
return fmt.Errorf("failed to iterate over tables result set: %w", err)
300+
iterErr := rs.Err()
301+
rs.Close()
302+
303+
if iterErr != nil {
304+
return fmt.Errorf("failed to iterate over tables result set: %w", iterErr)
303305
}
304306
}
305307

internal/component/database_observability/mysql/collector/setup_consumers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,9 @@ func (c *SetupConsumers) getSetupConsumers(ctx context.Context) error {
135135
}
136136
}
137137

138+
if err := rs.Err(); err != nil {
139+
return fmt.Errorf("failed to iterate over setup_consumers result set: %w", err)
140+
}
141+
138142
return nil
139143
}

0 commit comments

Comments
 (0)