Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Safely handle db.Iterator and itr.Error errors to prevent resource leaks #382

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

meetrick
Copy link

@meetrick meetrick commented Jan 4, 2025

Description

This PR modifies the error handling in PrintDBStats by replacing panic calls with returned errors. Specifically:

  • db.Iterator errors now return a formatted error instead of causing a panic.
  • itr.Error is also handled gracefully by returning an error.

Motivation

In the current code, if db.Iterator() or itr.Error() causes a panic,
the defer itr.Close() might not be called. Depending on the database
implementation, resources may not be automatically cleaned up, which could
result in:

  • Memory leaks.
  • File handle leaks.
  • Database lock issues.

This PR ensures that the iterator is closed properly even when errors occur.
If this behavior is already expected or deemed unnecessary, this PR can be
closed without merging.

…ce leaks

This PR modifies the error handling in PrintDBStats by replacing panic
calls with returned errors. Specifically:
- db.Iterator errors now return a formatted error instead of causing a panic.
- itr.Error is also handled gracefully by returning an error.

Signed-off-by: Hwangjae Lee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant