grpcproxy: new watchers may be added to a disconnected watchBroadcast and miss all subsequent events
Bug report criteria
- [x] This bug report is not security related, security issues should be disclosed privately via [email protected].
- [x] This is not a support request or question, support requests or questions should be raised in the etcd discussion forums.
- [x] You have read the etcd bug reporting guidelines.
- [x] Existing open issues along with etcd frequently asked questions have been checked and this is not a duplicate.
What happened?
In server/proxy/grpcproxy, when a watchBroadcast's underlying etcd watch connection is broken (the goroutine exits after for wr := range wch completes), the watchBroadcast remains in watchBroadcasts.bcasts with no indication that it is no longer receiving events.
This causes two problems:
-
add()can place new watchers into a dead broadcast: Since there is nostoppedflag,add()happily accepts new watchers into a broadcast whose goroutine has already exited. These watchers will never receive any subsequent events. -
coalesce()can migrate watchers into a dead broadcast: The coalesce logic only checksnextrevandresponses, not whether the target broadcast is still alive. Watchers migrated to a dead broadcast will also stop receiving events.
Additionally, there is no mechanism to reassign existing watchers (orphans) from a dead broadcast to a healthy one.
What did you expect to happen?
- A disconnected
watchBroadcastshould be marked as stopped and refuse new watchers. coalesce()should not migrate watchers to a stopped broadcast.- When a broadcast disconnects, its existing watchers should be automatically reassigned to a healthy broadcast or a newly created one.
How can we reproduce it (as minimally and precisely as possible)?
- Set up an etcd gRPC proxy with multiple client watchers coalesced on the same key range.
- Cause the backend etcd watch connection to break (e.g., network partition, etcd server restart).
- After the break, create a new watcher on the same key range through the proxy.
- Observe that the new watcher (and any existing watchers on the dead broadcast) never receives subsequent events.
Anything else we need to know?
No response
Etcd version (please run commands below)
$ etcd --version
v3.5.4
$ etcdctl version
v3.5.4
Etcd configuration (command line flags or environment variables)
paste your configuration here
Etcd debug information (please run commands below, feel free to obfuscate the IP address or FQDN in the output)
$ etcdctl member list -w table
# paste output here
$ etcdctl --endpoints=<member list> endpoint status -w table
# paste output here
Relevant log output
When a watch client's connection drops, the watchBroadcast remains in the proxy's tracking list but can no longer deliver events, yet new watchers that join while it is in this state are silently attached to the dead broadcast and never receive updates. This creates a silent data loss scenario where client applications believe they are subscribed to changes but are in fact receiving nothing. Adding a stopped flag to the broadcast struct and a check in the watcher-addition path to reassign new watchers to a live broadcast would prevent this class of issue. Is the stopped flag already present in any of the nearby watcher code, or would this require introducing a new field and updating the watcher registration logic?
The stopped flag does not currently exist in the proxy watch code. I've submitted a fix #21814 that addresses this issue.
Here's a summary of the changes:
-
Added a
stopped boolfield towatchBroadcast— it gets set totruewhen the underlying etcd watch channel closes (i.e., the goroutine exits afterfor wr := range wchcompletes). -
Guard in
add()—watchBroadcast.add()now checksif wb.stopped { return false }before attaching a new watcher, so no watcher can be silently added to a dead broadcast. -
Guard in
coalesce()— the coalescing logic now checks!wbswb.stoppedbefore migrating watchers to another broadcast, preventing migration to a dead one. -
Added a
reattachcallback — when a broadcast's goroutine exits (connection drop), it invokesreattach(wb)which collects all orphaned watchers from the dead broadcast and reassigns them to an existing live broadcast or creates a new one.
PR: https://github.com/etcd-io/etcd/pull/21814
cc @ahrtr @fuweid @jberkus
Can we announce deprecation of grpcproxy or are we still pretending someone is working on it?
Are there any recommended alternatives to grpcproxy? In our use case, we have a large number of watch streams and the watched data volume is significant, so we rely on the proxy to coalesce watches and optimize performance.
Can we announce deprecation of grpcproxy
I believe it's useful but we don't have bandwidth to take care of it.
Options:
- Deprecate it and eventually remove it
- Move it into a separate repo, and call for contributors.
Probably we can send a survey? @jberkus
I believe it's useful
Indeed. +1 for a separate repo.
Let's start this discussion somewhere other than an unrelated PR.
@jberkus @ahrtr — this issue (#21813) feels like a reasonable home for the grpcproxy discussion since the watch reliability problem here is one of the concrete symptoms that makes maintenance painful. If the preference is a dedicated tracking issue or a SIG-etcd agenda item instead, I am happy to open one.
A short survey of current grpcproxy users (how many rely on it in production, what for) seems like the right next step before deciding between deprecation and extraction.