Comments (7)
I guess it has to do with my lack of understanding on how to properly handle errors. https://dart.dev/guides/libraries/futures-error-handling.
It is also something that holds back #11
It is now clear, that we need to improve in this direction.
First step would be writing few unit tests.
from redis-dart.
I'll chime in here with some unsolicited observations. :)
I've only looked through this code briefly so I might be totally off base but here's what I noticed:
Starting here: https://github.com/ra1u/redis-dart/blob/master/lib/pubsub.dart#L15
The Future.doWhile
and the _senddummy
are future stacks without any error/exception handling. The _senddummy
in particular will only complete completer
with a success value from RedisParser.parseredisresponse
. So if RedisParser.parseredisresponse
throws that'll bubble up to the Future.doWhile
but never complete completer
. I think adding error path through that future stack that ultimately closes the PubSub._stream_controller
or passes an error to client listener should solve it...and it should be pretty straight forward to add.
from redis-dart.
Thank you for the quick reply!
One more tiny example to mention. For pubSub.listen() scenario, it would be nicer to capture the errors (e.g. Redis connection breaks) with onDone
or onError
. I made an example below.
await runZoned(() async {
pubSub = await PubSub(cmd);
}, onError: (error) {
print('>>>>> captured by runZoned wrapping PubSub'); //still print here
});
runZoned(() {
pubSub.getStream().listen((message) {
print(message);
}, onDone: () {
print('onDone'); //not print here
}, onError: (error) {
print('onError: $error'); //not print here
}, cancelOnError: true);
}, onError: (error) {
print('>>>>> captured by runZoned onError: $error'); //not print here
});
from redis-dart.
What is expected behavior if
RedisParser.parseredisresponse throws in PubSub?
Current naive implementations, throws this up to connection opener, so it has consequence of dropped connection.
Are we able to correctly recover trough same connection, so that we reuse all futures if we catch this error earlier?
What to do if redis server sends response we are unable to receive for some reason? Do we propagate error and then resume receiving further requests, like nothing happened?
I think there are two kinds of issues.
One is user generated exceptions, that he wants to propagate trough redis-dart stack and other is parser/connection generated errors.
When user exception throws (like DatabaseReceivedValueIsTooLargeTo Process or UserCredentialsInvalid) we need to correctly propagate this trough this stack, and this is something that is possible to recover, since connection and protocol is unaffected.
RedisConnection/protocol errors that happens less frequently is something that is probably impossible to recover from and best we can do is to notify that non recoverable error occurred.
Dart has similar approach using Errors
These are not errors that a caller should expect or catch - if they occur, the program is erroneous, and terminating the program may be the safest response
and Exception
It is intended to be caught, and it should contain useful data fields.
So maybe we should use Errors in our code to distinguish them from user kind of Exceptions.
When RedisError happens we terminate Connection and user is discouraged from catching them, and user exceptions needs to somehow propagate our redis-dart twisted callback stack.
from redis-dart.
I think the above makes A LOT of sense!
In our application we have a clearly typed Exceptions and Errors that extend the dart base classes for just this reason.
I think throwing an exception or error at the connection opener or constructor isn't a great since it's hard to catch those (like you'd have to wrap a constructor in a new zone to trap an error).
You could provide an error call back in the constructor but as a consumer I'd rather get my exception or error at the point of use, then my application can take the appropriate action then.
The commit above looks good, it doesn't include a fix for the OP's pubsub issue specifically but it could be easily extended address that. My only comment would be it would be nice if the RedisError
and TransactionError
implemented the dart:core exception or error interface; that'd be a bit more friendly.
from redis-dart.
@yeplato can you rerun test against recent master branch and report how it behaves regarding this reported issue. I am looking forward to close this.
from redis-dart.
Fixed in version 3.1.0. Please do test and DO REPORT issue if you still find one.
Reference example in https://github.com/ra1u/redis-dart/#pubsub
from redis-dart.
Related Issues (20)
- FormatException with Byte data on topic HOT 8
- How to authenticate in the connection? HOT 1
- JSON updates with $ - Expected an identifier by Dart HOT 1
- Redis doesn't work on flutter web HOT 1
- implement a way to automatically reconnect and resubscribe if the Redis server is restarted
- SocketException: Connection refused (OS Error: Connection refused, errno = 61), address = localhost, port = 56388 HOT 1
- How to check redis connect or not? is there any command to check ?
- While connecting to redis getting SocketException: Connection refused , address = localhost, port = 45042
- connect with authentication HOT 2
- refactor: Upgrade api to match latest dart conventions HOT 10
- JSON.GET <key> <JSON Path> not working HOT 2
- Redis dart licence change - Need your Feedback! HOT 7
- Connection cannot be closed HOT 2
- it's support redis cluster? HOT 1
- Example code
- Whether to support ssl connection HOT 1
- Does this plug-in support ssl? HOT 5
- how to cosume Redis Streams / Lists HOT 1
- RedisRuntimeError(got element that cant not be parsed) HOT 1
- Slow performance when reading from pub sub and adding to Redis Streams HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redis-dart.