Skip to content

Commit d70f304

Browse files
committed
feat: fix panic on empty Events array in etcd watch response (#36)
1 parent 2f2c69e commit d70f304

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ go 1.16
44

55
require (
66
github.com/casbin/casbin/v2 v2.30.2
7-
go.etcd.io/etcd/api/v3 v3.5.0
87
go.etcd.io/etcd/client/v3 v3.5.0
98
)

watcher.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ func (w *Watcher) Update() error {
164164
func (w *Watcher) startWatch() error {
165165
watcher := w.client.Watch(context.Background(), w.keyName)
166166
for res := range watcher {
167+
// Skip progress notifications
168+
if res.IsProgressNotify() {
169+
continue
170+
}
171+
// Skip empty events
172+
if len(res.Events) == 0 {
173+
continue
174+
}
167175
t := res.Events[0]
168176
if t.IsCreate() || t.IsModify() {
169177
w.lock.RLock()

0 commit comments

Comments
 (0)