jetcd
jetcd copied to clipboard
OnError() contract for io.etcd.jetcd.Listener is different from io.grpc.stub.StreamObserver
The behavior of io.etcd.jetcd.Listener is different from io.grpc.stub.StreamObserver wrt when (and how many times) to call onError. This is error-inviting, since the interfaces have exactly the same signatures: people familiar with gRPC APIs can assume StreamObserver behavior.
Some earlier discussion in https://github.com/etcd-io/jetcd/pull/819#issuecomment-688675196 and following comments.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.
when you use this method :
default Watcher watch(ByteSequence key, WatchOption option, Consumer<WatchResponse> onNext) {
return watch(key, option, listener(onNext));
}
If there have some runtime exception during invoke logic in "onNext" implementation, you will get nothing except "OUTBOUND RST_STREAM: streamId=5 errorCode=8" in log in debug level , the thrown exception is caught and mute , caluse the listener method:
static Listener listener(Consumer<WatchResponse> onNext) {
return listener(onNext, t -> {
}, () -> {
});
}
"onError" is empty. if you do not familiar with the api and you will spend some time to find out why the watch callback only invoke once.
if you use "com.ibm.etcd:etcd-java" library, you need to implement "io.grpc.stub.StreamObserver" which you have to override "onError" method , also you can find message "Watch stream cancelled due to there being no active watches" in log(info level) , this message may helps you to find out the really reson too .
@huayaoyue6 is there anything we can do to improve this case ?
@huayaoyue6 is there anything we can do to improve this case ?
may be @jcferretti72 is experienced in this case . or just like "com.ibm.etcd:etcd-java" do.
@huayaoyue6 the interface
default Watcher watch(ByteSequence key, WatchOption option, Consumer<WatchResponse> onNext) {
return watch(key, option, listener(onNext));
}
Is of course expected to mute exception as you don't provide any error handler so it is up to you to ensure that the implementation of onNext
does handles its exceptions. If you need to catch errors, there are a few other methods that add support to catch exceptions like:
https://github.com/etcd-io/jetcd/blob/38133bcad3148dcbc951f047e8532e3732986bb3/jetcd-core/src/main/java/io/etcd/jetcd/Watch.java#L41
or other variants.
Is there anything missing ?
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.