How to (synchronously) check Channel health?

Prefer Channel.isActive for this.

No, but there shouldn't be either.

If you are not on the Channel event loop then you cannot be confident that the Channel is healthy at any given point in time, because absent synchronisation there is no shared point in time. More importantly, if you're pooling channels, you already need to tolerate the possibility that the Channel was healthy when you checked, but became unhealthy in the time between checking and handing it off to the pool. That is, you have an unavoidable TOCTOU issue.

Instead, my recommendation is to attach a callback to the Channel's closeFuture that will fire and notify the pool. This will allow the pool to prune connections that die while they're pooled, and it will allow you to keep track of the channel's death/liveness state.

1 Like