Skip to content

Conversation

@glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Dec 3, 2025

Motivation:

In some rare situations the connection manager can leak a promise on deinit. The connection pool maintains the refs to these managers and they are only dropped in two situations:

  1. when the pool is shutdown
  2. when a quiescing connection is removed from the pool

When the pool is shutdown all conn managers are also shutdown (which will complete all promises stored in its state).

When a conn is going away the conn manager relies on events from the channel pipeline to inform it that it can close. When it closes the pool will remove the ref to the conn manager and do a few bits of cleanup. If the conn closes gracefully then all is well. However, if that isn't the case then a reconnect may kick in (creating new promises). At this point there is a conn manager attempting reconnects but which is no longer managed by the pool: this is a bug in and of itself.

The conn manager is also kept alive by a ref from the channel it is currently managing (via a channel handler), it's possible that at some point during the connection lifecycle that that ref is dropped and there's nothing keeping the conn manager alive, but this is speculative.

The fix for this is straightforward: for conn managers which are quiescing shut them down when they are removed from the pool.

Modifications:

  • Shutdown conn manager when its last connection is dropped

Result:

Fewer leaking promises

Motivation:

In some rare situations the connection manager can leak a promise on
deinit. The connection pool maintains the refs to these managers and
they are only dropped in two situations:

1. when the pool is shutdown
2. when a quiescing connection is removed from the pool

When the pool is shutdown all conn managers are also shutdown (which
will complete all promises stored in its state).

When a conn is going away the conn manager relies on events from the
channel pipeline to inform it that it can close. When it closes the pool
will remove the ref to the conn manager and do a few bits of cleanup.
If the conn closes gracefully then all is well. However, if that isn't
the case then a reconnect may kick in (creating new promises). At this
point there is a conn manager attempting reconnects but which is no
longer managed by the pool: this is a bug in and of itself.

The conn manager is also kept alive by a ref from the channel it is
currently managing (via a channel handler), it's possible that at some
point during the connection lifecycle that that ref is dropped and
there's nothing keeping the conn manager alive, but this is speculative.

The fix for this is straightforward: for conn managers which are
quiescing shut them down when they are removed from the pool.

Modifications:

- Shutdown conn manager when its last connection is dropped

Result:

Fewer leaking promises
@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Dec 3, 2025
@glbrntt glbrntt requested a review from gjcairo December 3, 2025 13:14
@glbrntt glbrntt enabled auto-merge (squash) December 3, 2025 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant