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

Error when streaming list of keys #35

Closed
HomelessDinosaur opened this issue Sep 3, 2024 · 0 comments
Closed

Error when streaming list of keys #35

HomelessDinosaur opened this issue Sep 3, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@HomelessDinosaur
Copy link
Member

HomelessDinosaur commented Sep 3, 2024

Iterating over a key stream like so:

// get a list of keys
final stream = await kv.keys();

// checks if a certain key exists in the kv store
final exists = await stream.any((key) => key == filterKey);

Will result in an error like so:

test-main [Running]: unhandled gRPC error: gRPC Error (code: 2, codeName: UNKNOWN, message: HTTP/2 error: Connection error: Connection is being forcefully terminated. (errorCode: 1), details: null, rawResponse: null, trailers: {})
test-main [Running]: unhandled gRPC error: gRPC Error (code: 2, codeName: UNKNOWN, message: HTTP/2 error: Connection error: Connection is being forcefully terminated. (errorCode: 1), details: null, rawResponse: null, trailers: {})
test-main [Running]: unhandled gRPC error: gRPC Error (code: 2, codeName: UNKNOWN, message: HTTP/2 error: Connection error: Connection is being forcefully terminated. (errorCode: 1), details: null, rawResponse: null, trailers: {})
test-main [Running]: unhandled gRPC error during handler execution: gRPC Error (code: 2, codeName: UNKNOWN, message: HTTP/2 error: Connection error: Connection is being forcefully terminated. (errorCode: 1), details: null, rawResponse: null, trailers: {})
test-main [Error]: Unhandled exception:
Bad state: Cannot add event after closing
#0      _StreamController.add (dart:async/stream_controller.dart:605:24)
#1      _StreamSinkWrapper.add (dart:async/stream_controller.dart:877:13)
#2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#4      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#5      _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
#6      _HandleErrorStream._handleData (dart:async/stream_pipe.dart:253:10)
#7      _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
#8      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#9      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#10     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#11     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
#12     _MapStream._handleData (dart:async/stream_pipe.dart:218:10)
#13     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
#14     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#15     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#16     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#17     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
#18     _MapStream._handleData (dart:async/stream_pipe.dart:218:10)
#19     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
#20     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#21     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#22     _DelayedData.perform (dart:async/stream_impl.dart:541:14)
#23     _PendingEvents.handleNext (dart:async/stream_impl.dart:646:11)
#24     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:617:7)
#25     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#26     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#27     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#28     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)

The solution is to use an await for instead of any.

// checks if a certain key exists in the kv store
var exists = false;
await for (var key in keys) {
  if (key == favourite.name) {
    exists = true;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant