Skip to content

StreamQueue throws 'Bad state: No elements' unexpectedly. #50217

Closed
@Cat-sushi

Description

@Cat-sushi

Dart SDK version: 2.18.2 (stable) (Unknown timestamp) on "linux_x64"
AOT compiled.

There are 6 sendReceve invocations, and 3 of them throws "Bad state: No elements" at invocation await queries.next.
There is no await between await queries.hasNext and await queries.next.

VM mode crashes for another or same reason of #50082.

  var queryList = ['A', 'B', 'C'];
  var queries = StreamQueue<String>(Stream.fromIterable(queryList));

  ...

  Future<void> sendReceve() async {
    while (await queries.hasNext) {
      var ix = ixS;
      ixS++;
      var query = ''; // TODO
      try {
        query = await queries.next; // TODO sometimes unexpectedly throws 'Bad state: No elements'
      } catch (e, s) {
        print(e);
        print(s);
      }
      var client = await serverPool.next;
      var result = await client.fmatch(query);
      serverPoolController.add(client);
      results[ix] = result;
      printResultsInOrder();
    }
  }
Bad state: No elements
#0      _NextRequest.update (package:async/src/stream_queue.dart:695)
#1      StreamQueue._updateRequests (package:async/src/stream_queue.dart:419)
#2      StreamQueue._close (package:async/src/stream_queue.dart:513)
#3      StreamQueue._ensureListening.<anonymous closure> (package:async/src/stream_queue.dart:481)
#4      _RootZone.runGuarded (dart:async/zone.dart:1574)
#5      _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:392)
#6      _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:402)
#7      _BufferingStreamSubscription._close (dart:async/stream_impl.dart:291)
#8      _MultiStreamController.closeSync (dart:async/stream_impl.dart:1058)
#9      new Stream.fromIterable.<anonymous closure>.next (dart:async/stream.dart:383)
#10     _microtaskLoop (dart:async/schedule_microtask.dart:40)
#11     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49)
#12     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:122)
#13     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:193)

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-as-intendedClosed as the reported issue is expected behaviorneeds-infoWe need additional information from the issue author (auto-closed after 14 days if no response)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions