Skip to content

Commit cb487c4

Browse files
committed
fix: dispose deferred scale-down connection during DisposeAsync
When DisposeAsync runs while _deferredScaleDownConnection is non-null, the connection was leaked. This happens when a shrink task completes and the connection is deferred (waiting for in-flight requests to drain for partition affinity), but DisposeAsync is called before the drain finishes. The connection is already removed from _pinnedConnections by the shrink task, so it isn't reached by any other disposal path.
1 parent 868e197 commit cb487c4

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/Dekaf/Producer/BrokerSender.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,6 +2482,17 @@ public async ValueTask DisposeAsync()
24822482
_drainingConnection = null;
24832483
}
24842484

2485+
// Dispose deferred scale-down connection if present. This connection was removed from
2486+
// _pinnedConnections by the shrink task but hasn't been applied via ApplyScaleDown yet
2487+
// (waiting for in-flight requests to drain). It's not tracked anywhere else, so we must
2488+
// dispose it explicitly here to avoid a resource leak.
2489+
if (_deferredScaleDownConnection is not null)
2490+
{
2491+
try { await _deferredScaleDownConnection.DisposeAsync().ConfigureAwait(false); }
2492+
catch (Exception ex) { LogBatchCleanupStepFailed(ex, _brokerId); }
2493+
_deferredScaleDownConnection = null;
2494+
}
2495+
24852496
var totalPending = _totalPendingResponseCount;
24862497
if (totalPending > 0)
24872498
{

0 commit comments

Comments
 (0)