Skip to content

Conversation

@WhyNotHugo
Copy link
Contributor

@WhyNotHugo WhyNotHugo commented Oct 16, 2025

Implement a Client.Closed() to be used by clients to monitor when a connection is closed.

@WhyNotHugo
Copy link
Contributor Author

I've implemented by particular case in some other way, but this sounds useful to have. I have no strong objections if you'd prefer to close this PR.

@emersion
Copy link
Owner

emersion commented Nov 1, 2025

I was wondering about the use-case for this. I initially thought I needed something similar for alps, but then figured it wouldn't help much:

  • The connection might be broken even when the reader goroutine is still alive, when a connection isn't explicitly closed by the remote and times out.
  • Even if the reader goroutine could perfectly detect when a connection is broken, checking for the closed channel introduced in this PR before sending a command would be racy.
  • A disconnected client only consumes a small amount of memory, its underlying FD is closed.

@WhyNotHugo
Copy link
Contributor Author

WhyNotHugo commented Nov 5, 2025

checking for the closed channel introduced in this PR before sending a command would be racy.

The channel is not intended to be checked before sending a message, but to re-connect automatically when the connection terminates (i.e.: in the case of NOTIFY).

@WhyNotHugo
Copy link
Contributor Author

WhyNotHugo commented Nov 5, 2025

Previously, the Notify.Overflow channel in #718 would also be closed when the connection dropped (a convenient side-effect). This allowed me to detect when a connection had been closed.

Having switched NOTIFY to use a UnilateralDataHandler for NOTIFYOVERFLOW events, I once again need this feature.

I don't think I have any other way of detecting when the connection has been closed. I'm only waiting for NOTIFY events, so never send any messages.

@emersion
Copy link
Owner

emersion commented Nov 9, 2025

Hm, right, that's a good point. I think NOTIFY is special here: with IDLE, clients could call IdleCommand.Wait to figure out when the connection was broken. Since NOTIFY isn't a long-running command, there's no equivalent.

Implement a Client.Closed() to be used by clients to monitor when a
connection is closed.
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