Skip to content

Conversation

@kangqiao
Copy link

Description

Fixes inconsistent cache key format in _ConnectionManager that causes memory leak.

Problem

In connection_manager_imp.dart, the cache key format is inconsistent:

Location Variable Format Example
Line 50 getConnection transportCacheKey scheme://host:port https://example.com:443
Line 91 _connect domain host:port example.com:443

When idle timeout fires (line 146), _transportsMap.remove(domain) fails to find the key, causing entries to never be removed.

Impact

  • Memory leak: _transportsMap entries are never cleaned up
  • Map pollution over long-running applications

Solution

Changed domain format to match transportCacheKey:

// Before
final domain = '${uri.host}:${uri.port}';

// After
final domain = '${uri.scheme}://${uri.host}:${uri.port}';

…anager

The cache key format was inconsistent between getConnection() and _connect(),
causing _transportsMap.remove() to fail silently during idle timeout cleanup.

- getConnection uses: '${uri.scheme}://${uri.host}:${uri.port}'
- _connect was using: '${uri.host}:${uri.port}'

This led to memory leaks as entries were never removed from _transportsMap.
@kangqiao kangqiao requested a review from a team as a code owner January 27, 2026 07:36
@github-actions
Copy link
Contributor

Code Coverage Report: Only Changed Files listed

Package Base Coverage New Coverage Difference
Overall Coverage 🟢 87.95% 🟢 87.95% ⚪ 0%

Minimum allowed coverage is 0%, this run produced 87.95%

@AlexV525
Copy link
Member

@kangqiao Good catch! Would you add a test case regarding the fix?

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.

2 participants