Fix resource leak on close error in SessionFactory#1448
Open
jgowdy-godaddy wants to merge 2 commits intomainfrom
Open
Fix resource leak on close error in SessionFactory#1448jgowdy-godaddy wants to merge 2 commits intomainfrom
jgowdy-godaddy wants to merge 2 commits intomainfrom
Conversation
jgowdy-godaddy
added a commit
that referenced
this pull request
Aug 3, 2025
This issue has been fixed in PR #1448, so removing it from the remediation document as requested. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
aka-bo
reviewed
Aug 20, 2025
Contributor
aka-bo
left a comment
There was a problem hiding this comment.
Looks good. Nice error collection pattern and the tests cover the scenarios well.
The .tool-versions file needs to be removed from the PR though.
Prevents resource leaks by ensuring all Close() operations are attempted and all errors are collected and returned. Previously, if intermediate cache close failed but system cache close succeeded, the first error was lost and resources could remain unfreed. Changes: - Collect all close errors instead of returning early - Return combined error message when multiple close operations fail - Ensure all resources are attempted to be closed regardless of failures - Add comprehensive tests for all error scenarios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Split TestSessionFactory_Close_ErrorHandling into two functions - Extracted test execution logic into testSessionFactoryCloseError helper - Reduces function length from 84 lines to under 70 line limit
0b73665 to
77c164e
Compare
jgowdy-godaddy
added a commit
that referenced
this pull request
Oct 8, 2025
This issue has been fixed in PR #1448, so removing it from the remediation document as requested. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a critical resource leak vulnerability in the
SessionFactory.Close()method where errors from intermediate cache closure could be silently lost, potentially leaving resources unfreed in production systems.Issue Analysis
The Problem
The original code in
session.go:97-100had a resource management flaw:Critical Issues:
f.intermediateKeys.Close()fails butf.systemKeys.Close()succeeds, the first error is completely lostWhy This Matters
Solution
The Fix
Collect all errors and ensure all cleanup operations are attempted:
Key Improvements
Testing
Added comprehensive test coverage for all error scenarios:
Test Cases Covered
intermediate_error_only: Intermediate cache fails, system cache succeedssystem_error_only: System cache fails, intermediate cache succeedsboth_errors: Both caches fail with different errorsno_shared_cache_system_error: System error when shared cache disabledno_errors: All operations succeed (regression test)Example Test Results
Performance Impact
Validation
Impact
This fix prevents production resource leaks and improves system reliability by:
The solution follows Go best practices for resource management and error handling without introducing external dependencies.
🤖 Generated with Claude Code