Skip to content

fix(scan): improve resource management in scanIterator #1

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

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

Conversation

pranavkonde
Copy link

@pranavkonde pranavkonde commented Jun 2, 2025

Improve Resource Management in scanIterator

Problem

  • Potential resource leaks when context is cancelled during operation
  • Race conditions possible due to unordered channel closing
  • Inadequate error propagation from worker goroutines

Solution

  • Added error channel for proper worker error handling
  • Implemented ordered cleanup sequence in Close() method
  • Enhanced context cancellation handling
  • Improved worker synchronization

Changes

type scanIterator struct {
    // ... existing fields ...
    errChan   chan error    // New error channel
}

func (s *scanIterator) Close() error {
    s.closeOnce.Do(func() {
        if s.cancel != nil {
            s.cancel()
        }
        s.doneWG.Wait()
        close(s.errChan)
        close(s.resultChan)
    })
    return nil
}

Testing

  • Verified with context cancellation scenarios
  • Tested concurrent operation cases
  • Checked error propagation paths

Checklist

  • Code follows project guidelines
  • Changes are focused and atomic
  • Manually tested

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