Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: canceled should always be set to true when cancel a watch request #373

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions pkg/logstructured/logstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,17 +425,20 @@ func (l *LogStructured) Watch(ctx context.Context, prefix string, revision int64
}

result := make(chan []*server.Event, 100)
wr := server.WatchResult{Events: result}
errc := make(chan error, 1)
wr := server.WatchResult{Events: result, Errorc: errc}

rev, kvs, err := l.log.After(ctx, prefix, revision, 0)
if err != nil {
if !errors.Is(err, context.Canceled) {
logrus.Errorf("Failed to list %s for revision %d: %v", prefix, revision, err)
}
if err == server.ErrCompacted {
compact, _ := l.log.CompactRevision(ctx)
wr.CompactRevision = compact
wr.CurrentRevision = rev
if err == server.ErrCompacted {
compact, _ := l.log.CompactRevision(ctx)
wr.CompactRevision = compact
wr.CurrentRevision = rev
} else {
errc <- server.ErrGRPCUnhealthy
}
}
cancel()
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
var (
ErrNotSupported = status.New(codes.InvalidArgument, "etcdserver: unsupported operations in txn request").Err()

ErrKeyExists = rpctypes.ErrGRPCDuplicateKey
ErrCompacted = rpctypes.ErrGRPCCompacted
ErrFutureRev = rpctypes.ErrGRPCFutureRev
ErrKeyExists = rpctypes.ErrGRPCDuplicateKey
ErrCompacted = rpctypes.ErrGRPCCompacted
ErrFutureRev = rpctypes.ErrGRPCFutureRev
ErrGRPCUnhealthy = rpctypes.ErrGRPCUnhealthy
)

type Backend interface {
Expand Down Expand Up @@ -85,6 +86,7 @@ type WatchResult struct {
CurrentRevision int64
CompactRevision int64
Events <-chan []*Event
Errorc <-chan error
}

func unsupported(field string) error {
Expand Down
9 changes: 7 additions & 2 deletions pkg/server/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ func (w *watcher) Start(ctx context.Context, r *etcdserverpb.WatchCreateRequest)
}
}

w.Cancel(id, 0, 0, nil)
select {
case err := <-wr.Errorc:
w.Cancel(id, 0, 0, err)
default:
w.Cancel(id, 0, 0, nil)
}
logrus.Tracef("WATCH CLOSE id=%d, key=%s", id, key)
}()
}
Expand Down Expand Up @@ -219,7 +224,7 @@ func (w *watcher) Cancel(watchID, revision, compactRev int64, err error) {

serr := w.server.Send(&etcdserverpb.WatchResponse{
Header: txnHeader(revision),
Canceled: err != nil,
Canceled: true,
CancelReason: reason,
WatchId: watchID,
CompactRevision: compactRev,
Expand Down
Loading