mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #4489 from heyitsanthony/fix-watcher-reqresend
clientv3: fix bad variable capture in watch request retry
This commit is contained in:
commit
a78826e025
@ -157,6 +157,33 @@ func testWatchMultiWatcher(t *testing.T, wctx *watchctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestWatchReconnRequest tests the send failure path when requesting a watcher.
|
||||||
|
func TestWatchReconnRequest(t *testing.T) {
|
||||||
|
runWatchTest(t, testWatchReconnRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testWatchReconnRequest(t *testing.T, wctx *watchctx) {
|
||||||
|
// take down watcher connection
|
||||||
|
donec := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
wctx.wclient.ActiveConnection().Close()
|
||||||
|
select {
|
||||||
|
case <-donec:
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// should reconnect when requesting watch
|
||||||
|
if wctx.ch = wctx.w.Watch(context.TODO(), "a", 0); wctx.ch == nil {
|
||||||
|
t.Fatalf("expected non-nil channel")
|
||||||
|
}
|
||||||
|
close(donec)
|
||||||
|
// ensure watcher works
|
||||||
|
putAndWatch(t, wctx, "a", "a")
|
||||||
|
}
|
||||||
|
|
||||||
// TestWatchReconnInit tests watcher resumes correctly if connection lost
|
// TestWatchReconnInit tests watcher resumes correctly if connection lost
|
||||||
// before any data was sent.
|
// before any data was sent.
|
||||||
func TestWatchReconnInit(t *testing.T) {
|
func TestWatchReconnInit(t *testing.T) {
|
||||||
|
@ -286,13 +286,13 @@ func (w *watcher) run() {
|
|||||||
|
|
||||||
// send failed; queue for retry
|
// send failed; queue for retry
|
||||||
if failedReq != nil {
|
if failedReq != nil {
|
||||||
go func() {
|
go func(wr *watchRequest) {
|
||||||
select {
|
select {
|
||||||
case w.reqc <- pendingReq:
|
case w.reqc <- wr:
|
||||||
case <-pendingReq.ctx.Done():
|
case <-wr.ctx.Done():
|
||||||
case <-w.donec:
|
case <-w.donec:
|
||||||
}
|
}
|
||||||
}()
|
}(pendingReq)
|
||||||
failedReq = nil
|
failedReq = nil
|
||||||
pendingReq = nil
|
pendingReq = nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user