Skip to content

Fix connection cache eviction - #55

Open
salva wants to merge 2 commits into
masterfrom
fix/connection-cache-eviction
Open

Fix connection cache eviction#55
salva wants to merge 2 commits into
masterfrom
fix/connection-cache-eviction

Conversation

@salva

@salva salva commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes two bugs in Net::OpenSSH::ConnectionCache:

  • Failed cache entries were never deleted because the cleanup expression short-circuited on any defined object.
  • Undef cache entries could cause a method call on undef during cleanup.
  • The cache-size eviction loop stopped while the cache was still at or above the configured maximum.

Changes

  • Rewrite failed/undef entry cleanup explicitly.
  • Reverse the cache-size stop condition so eviction can run until the cache drops below the limit.
  • Add a regression test covering undef, failed, and live cache entries.
  • Add the new test file to MANIFEST.

Fixes #35.
Fixes #36.

Testing

  • perl -Ilib -c lib/Net/OpenSSH/ConnectionCache.pm
  • perl -Ilib t/connection-cache.t

Copilot AI review requested due to automatic review settings June 4, 2026 11:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes eviction/cleanup behavior in Net::OpenSSH::ConnectionCache so that failed/undef entries are removed correctly and the cache-size eviction loop can run until the cache drops below the configured limit (making room for a new entry). It also adds a regression test to cover the previously broken cleanup paths.

Changes:

  • Fix cleanup logic so failed cache entries are deleted and undef entries don’t trigger method calls.
  • Fix eviction-loop stop condition so the loop can actually evict/weak-delete entries until the cache is below the threshold.
  • Add a regression test for live/failed/undef entries and include it in MANIFEST.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/Net/OpenSSH/ConnectionCache.pm Rewrites cache cleanup and corrects the eviction loop stop condition.
t/connection-cache.t Adds regression coverage for undef/failed/live cache entries and clean_cache behavior.
MANIFEST Includes the new test file in the distribution manifest.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/Net/OpenSSH/ConnectionCache.pm Outdated
Comment on lines +30 to +34
for (keys %cache) {
$ssh = $cache{$_};
delete $cache{$_} unless $ssh and $ssh->error != OSSH_MASTER_FAILED;
}
for (keys %cache) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 195af61 by reindenting the cleanup block to match the surrounding 4-space style. Re-ran perl -Ilib -c lib/Net/OpenSSH/ConnectionCache.pm and perl -Ilib t/connection-cache.t.

Comment thread t/connection-cache.t Outdated
Comment on lines +42 to +43
ok((keys %Net::OpenSSH::ConnectionCache::cache) <= $Net::OpenSSH::ConnectionCache::MAX_SIZE,
'cache is reduced below the configured maximum');

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 195af61 by aligning the assertion text with the <= MAX_SIZE condition. Re-ran perl -Ilib t/connection-cache.t.

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.

ConnectionCache cache-size eviction stop condition is reversed ConnectionCache failed-entry cleanup is inverted

2 participants