Open
Description
Describe the bug
i try to cancel a watch with below code, but failed.
To Reproduce
using Etcdserverpb;
using Google.Protobuf;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace dotnet_etcd
{
class TestCancelWatch
{
dotnet_etcd.EtcdClient myConsulClient;
const long WID = 4445;
public void Start()
{
myConsulClient = new dotnet_etcd.EtcdClient("http://127.0.0.1:2379");
WatchKey("/zzz");
}
public void Stop()
{
UnWatch();
}
void WatchKey(string keyName)
{
WatchRequest req = new WatchRequest {
CreateRequest = new WatchCreateRequest
{
Key = ByteString.CopyFromUtf8(keyName),
WatchId = WID,
}
};
myConsulClient.Watch(req, (Etcdserverpb.WatchResponse respon) => {
Debug.Assert(respon.WatchId == WID);
Console.WriteLine("watch event!!!");
});
}
// unwatch
public void UnWatch()
{
WatchRequest req = new WatchRequest
{
CancelRequest = new WatchCancelRequest
{
WatchId = WID
}
};
myConsulClient.Watch(req, (Etcdserverpb.WatchResponse respon) => {
// never be executed!!!! bug?
Console.WriteLine($"cancel:{respon.Canceled}: {respon.CancelReason}");
});
}
}
class Program
{
static void Main(string[] args)
{
var watch = new TestCancelWatch();
while (true)
{
var str = Console.ReadLine();
if (str == "s")
{
watch.Start();
}
else if (str == "u")
{
watch.Stop();
}
}
}
}
}
Expected behavior
input 's'
input 'u'
console print "cancel: ..."
Screenshots
Additional context
dotnet-etcd: 3.0.0
etcd:3.4.3