Skip to content

feat: fix panic on empty Events array in etcd watch response#36

Merged
nomeguy merged 3 commits intomasterfrom
copilot/fix-etcd-watcher-empty-events
Jan 13, 2026
Merged

feat: fix panic on empty Events array in etcd watch response#36
nomeguy merged 3 commits intomasterfrom
copilot/fix-etcd-watcher-empty-events

Conversation

Copy link
Contributor

Copilot AI commented Jan 13, 2026

etcd watch responses can contain progress notifications or empty event arrays, causing res.Events[0] to panic with index out of bounds.

Changes

  • Added check for IsProgressNotify() to skip health check/keep-alive messages
  • Added length check before accessing res.Events[0] to handle empty arrays
func (w *Watcher) startWatch() error {
    watcher := w.client.Watch(context.Background(), w.keyName)
    for res := range watcher {
        // Skip progress notifications
        if res.IsProgressNotify() {
            continue
        }
        // Skip empty events
        if len(res.Events) == 0 {
            continue
        }
        t := res.Events[0]
        // ... rest of event processing
    }
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • go.etcd.io
    • Triggering command: /update-job-proxy /update-job-proxy -c=4 (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy DROP ache/go/1.24.11/--global test -e ntrust_Root_Certgit@github.com/ ache/go/1.24.11//usr/share/ca-certificates/mozilla/SecureTrust_CA.crt (dns block)
  • go.googlesource.com
    • Triggering command: /update-job-proxy /update-job-proxy -c=4 (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy DROP ache/go/1.24.11/--global test -e ntrust_Root_Certgit@github.com/ ache/go/1.24.11//usr/share/ca-certificates/mozilla/SecureTrust_CA.crt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>etcd watcher events maybe empty</issue_title>
<issue_description>etcd watcher RequestProgress maybe send message empty event; t := res.Events[0] will panic

func (w *Watcher) startWatch() error {
	watcher := w.client.Watch(context.Background(), w.keyName)
	for res := range watcher {
                // to check ProgressNotify
		if res.IsProgressNotify() {
			continue
		}
		t := res.Events[0]
		if t.IsCreate() || t.IsModify() {
			w.lock.RLock()
			//ignore self update
			if rev := t.Kv.ModRevision; rev > w.lastSentRev && w.callback != nil {
				w.callback(strconv.FormatInt(rev, 10))
			}
			w.lock.RUnlock()
		}
	}
	return nil
}</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@nomeguy nomeguy marked this pull request as ready for review January 13, 2026 17:26
@coveralls
Copy link

coveralls commented Jan 13, 2026

Coverage Status

coverage: 80.808% (-3.2%) from 84.043%
when pulling bec95a9 on copilot/fix-etcd-watcher-empty-events
into 2f2c69e on master.

Copilot AI and others added 2 commits January 13, 2026 17:32
Add checks for IsProgressNotify() and empty Events slice to prevent panic when accessing res.Events[0]

Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic when etcd watcher receives empty events Fix panic on empty Events array in etcd watch response Jan 13, 2026
Copilot AI requested a review from nomeguy January 13, 2026 17:35
@nomeguy nomeguy changed the title Fix panic on empty Events array in etcd watch response feat: fix panic on empty Events array in etcd watch response Jan 13, 2026
@nomeguy nomeguy merged commit 76159dc into master Jan 13, 2026
3 of 5 checks passed
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.

etcd watcher events maybe empty

4 participants