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

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: stream is closed #16

Closed
Peter-717 opened this issue Dec 13, 2019 · 7 comments
Closed

Comments

@Peter-717
Copy link

First of all, thank you so much for your library! We are using your redis-dart in our project.

Everything works well for us except the close() on a redisconnection. It throws on the console: "[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: stream is closed", despite a try and catch in our call (see snippet below where _redisConnection is the "single" instance of RedisConnection())

Future closeRedisConnection() async {
bool _close;

try {
  await _redisConnection.close();
  _close = true;
} catch (onError) {
  print('Redis Close Error: $onError');
}
return _close ?? false;

}

@ra1u
Copy link
Owner

ra1u commented Dec 14, 2019

Thank You for your input.

Seems to be connected with #15 and I have to admit that I was not able to make much of an progress since. I will try to take another look and I hope to move this issue forward.

@ra1u
Copy link
Owner

ra1u commented Dec 14, 2019

@Peter-717 are you able to write code in way to be included in test and to reproduce bug. You can publish code here in this thread or other way you find appropriate. That would be valuable in better understanding of Your particular issue and might additionally benefit other users.

Kind regards, Luka

@Peter-717
Copy link
Author

Hi Luka,
Here is the code. This is basically the Flutter starter app. The Floating button calls the .close() that generates the issue.

I am using a local Redis Server. And I am subscribing to the 'test' channel. When I publish any message on that channel, it will be displayed in the app.

Let me know if I can be of any further assistance. Thanks!

Note: One more thing, how can test that the connection is still alive with the server, as in PubSub mode, we can no longer send a PING command. Thanks

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:redis/redis.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Pub Sub Redis'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;

@OverRide
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State{
String messageRedis;
String now;
Command _command;
Stream stream;
StreamSubscription subscription;
RedisConnection _redisConnection = new RedisConnection();
PubSub pubSub;

Future finish() async {
pubSub.unsubscribe(['']);
await subscription.cancel();

try {
  await _redisConnection.close();
} on HandleUncaughtErrorHandler catch(e) {
  print('HandleUncaught: $e');
}

}

Future generateConnect() async {
print('In generate connect');
try {
_command = await _redisConnection.connect('127.0.0.1', 6379);

} on HandleUncaughtErrorHandler catch(e) {
  print('Generate Connect ERROR: $e');
  if (e.toString().contains('SocketException')){
    print('Caught the socket Exception');
  }
}
return _command;

}

Future startRedis() async {
try {
Command command = await generateConnect();
pubSub = PubSub(command);
pubSub.subscribe(['test']);
stream = pubSub.getStream();

  onData(dynamic value){
    setState(() {
      messageRedis = value.toString();
      now = DateTime.now().toString();
    });
  }

  subscription = stream.listen(onData);
} on Exception catch (e) {
  print('Start Redis: $e');
}

}

@OverRide
void initState() {
super.initState();
startRedis();
}

@OverRide
void dispose() {
subscription.cancel();
super.dispose();
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
now ?? 'Nothing yet',),
Text(messageRedis ?? 'No message yet',
style: Theme.of(context).textTheme.display1),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {await finish();},
tooltip: 'Increment',
child: Icon(Icons.stop),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}

@idrats
Copy link

idrats commented May 25, 2020

I faced with practically the same error. In my case it was Bad state: StreamSink is closed
You can reproduce it simply making 2 calls of redis with the same key immediately

@ra1u
Copy link
Owner

ra1u commented May 25, 2020

@idrats Thak you for report.

Can you please post short and working example of code, so that we are able to reproduce this?

@idrats
Copy link

idrats commented May 25, 2020

Sorry, I have figured out, that was my mistake

@ra1u
Copy link
Owner

ra1u commented May 25, 2020

@idrats that is great :)

I am now closing this, since we did made some progress in recent release, for this thing.
If someone finds an issue, please do open new issue and if possible post code to reproduce this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants