Code triggers assert in http code (dart:io) #13293

Closed
floitschG opened this Issue Sep 13, 2013 · 3 comments

Projects

None yet

4 participants

@floitschG
Member

Reported by Otskimanot Sqilal on stack-overflow:

The following code triggers an assert in checked mode:
Breaking on exception: 'dart:async/stream_impl.dart': Failed assertion: line 149 pos 12: '! _isClosed' is not true.

import 'dart:io';

import 'package:unittest/unittest.dart';

void main() {
  test('check if sent data equals expected data', () {

    HttpServer.bind('127.0.0.1', 8080)
      .then(expectAsync1((HttpServer server) {
        server.listen((HttpRequest request) {
          expect(request.runtimeType.toString(), equals('_HttpRequest'));
          request.fold(new BytesBuilder(), (prev, next) {
            prev.addAll(next);
            return prev;
          })
          .then(expectAsync1((BytesBuilder bb) {
            var bytes = bb.takeBytes(),
                helloString = new String.fromCharCodes(bytes);
            expect(helloString, equals('hello'));
            request.response.write(helloString);
            request.response.close();
            server.close();
          }));
        });
      }));

    HttpClient client = new HttpClient();
    client.get('127.0.0.1', 8080, '/')
      .then((HttpClientRequest request) {
        request.add('hello'.codeUnits);
        return request.close();
      });

  });
}

@floitschG
Member

cc @lrhn.

@sgjesse
Member
sgjesse commented Sep 13, 2013

The error reported does not show up on ToT. Running the code yield

unittest-suite-wait-for-done
PASS: check if sent data equals expected data

All 1 tests passed.
unittest-suite-success
Uncaught Error: HttpException: Content size exceeds specified contentLength. 5 bytes written while expected 0. [hello], uri = http://127.0.0.1:8081/
Stack Trace:
#­0 _HttpOutgoing.addStream.<anonymous closure> (http_impl.dart:793:7)
#­1 _Future._propagateToListeners.<anonymous closure> (dart:async/future_impl.dart:278:55)
#­3 _ZoneBase._runInZone (dart:async/zone.dart:82:17)
#­4 _ZoneBase._runUnguarded (dart:async/zone.dart:102:22)
#­5 _ZoneBase.executeCallback (dart:async/zone.dart:58:23)
#­6 _Future._propagateToListeners (dart:async/future_impl.dart:259:37)
#­7 _Future._completeError (dart:async/future_impl.dart:193:26)
#­8 _Future._asyncCompleteError.<anonymous closure> (dart:async/future_impl.dart:218:21)
#­9 _asyncRunCallback (dart:async/event_loop.dart:9:15)
#­10 _createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:8:13)
#­11 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:95:21)
#­12 _Timer._createTimerHandler.<anonymous closure> (timer_impl.dart:111:23)
#­13 _ReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:81:92)

Unhandled exception:
HttpException: Content size exceeds specified contentLength. 5 bytes written while expected 0. [hello], uri = http://127.0.0.1:8081/
#­0 _DefaultZone.handleUncaughtError.<anonymous closure> (dart:async/zone.dart:132:7)
#­1 _asyncRunCallback (dart:async/event_loop.dart:9:15)
#­2 _asyncRunCallback (dart:async/event_loop.dart:13:7)
#­3 _createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:8:13)
#­4 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:95:21)
#­5 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:103:7)
#­6 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:103:7)
#­7 _Timer._createTimerHandler.<anonymous closure> (timer_impl.dart:111:23)
#­8 _ReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:81:92)

Changing client.get to client.port to fix that causes the following error:

unittest-suite-wait-for-done
PASS: check if sent data equals expected data

All 1 tests passed.
unittest-suite-success
unittest-suite-wait-for-done
Uncaught Error: Bad state: No valid test. Did you forget to run your test inside a call to test()?
Stack Trace:
#­0 _SpreadArgsHelper._SpreadArgsHelper (package:unittest/unittest.dart:395:7)
#­1 expectAsync1 (package:unittest/unittest.dart:516:14)
#­2 main.<anonymous closure>.<anonymous closure>.<anonymous closure> (file:///usr/local/prj/dart/git/dart/xxx.dart:16:29)
#­3 _BufferingStreamSubscription._sendData.<anonymous closure> (dart:async/stream_impl.dart:184:55)
#­4 _ZoneBase._runInZone (dart:async/zone.dart:82:17)
#­5 _ZoneBase._runGuarded (dart:async/zone.dart:99:22)
#­6 _ZoneBase.executePeriodicCallbackGuarded (dart:async/zone.dart:68:21)
#­7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:184:41)
#­8 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:135:16)
#­9 _StreamController&_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:198:23)
#­10 _StreamController._add (dart:async/stream_controller.dart:130:16)
#­11 _StreamController.add (dart:async/stream_controller.dart:104:9)
#­12 _HttpServer._handleRequest (http_impl.dart:1408:20)
#­13 _HttpConnection._HttpConnection.<anonymous closure> (http_impl.dart:1313:33)
#­14 _BufferingStreamSubscription._sendData.<anonymous closure> (dart:async/stream_impl.dart:184:55)
#­15 _ZoneBase._runInZone (dart:async/zone.dart:82:17)
#­16 _ZoneBase._runGuarded (dart:async/zone.dart:99:22)
#­17 _ZoneBase.executePeriodicCallbackGuarded (dart:async/zone.dart:68:21)
#­18 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:184:41)
#­19 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:135:16)
#­20 _StreamController&_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:198:23)
#­21 _StreamController._add (dart:async/stream_controller.dart:130:16)
#­22 _StreamController.add (dart:async/stream_controller.dart:104:9)
#­23 _HttpParser._doParse (http_parser.dart:428:24)
#­24 _HttpParser._parse (http_parser.dart:160:15)
#­25 _onData (http_parser.dart:510:11)
#­26 _BufferingStreamSubscription._sendData.<anonymous closure> (dart:async/stream_impl.dart:184:55)
#­27 _ZoneBase._runInZone (dart:async/zone.dart:82:17)
#­28 _ZoneBase._runGuarded (dart:async/zone.dart:99:22)
#­29 _ZoneBase.executePeriodicCallbackGuarded (dart:async/zone.dart:68:21)
#­30 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:184:41)
#­31 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:135:16)
#­32 _StreamController&_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:198:23)
#­33 _StreamController._add (dart:async/stream_controller.dart:130:16)
#­34 _StreamController.add (dart:async/stream_controller.dart:104:9)
#­35 _onData (dart:io-patch/socket_patch.dart:833:42)
#­36 _BufferingStreamSubscription._sendData.<anonymous closure> (dart:async/stream_impl.dart:184:55)
#­37 _ZoneBase._runInZone (dart:async/zone.dart:82:17)
#­38 _ZoneBase._runGuarded (dart:async/zone.dart:99:22)
#­39 _ZoneBase.executePeriodicCallbackGuarded (dart:async/zone.dart:68:21)
#­40 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:184:41)
#­41 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:135:16)
#­42 _StreamController&_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:198:23)
#­43 _StreamController._add (dart:async/stream_controller.dart:130:16)
#­44 _StreamController.add (dart:async/stream_controller.dart:104:9)
#­45 _RawSocket._RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:550:52)
#­46 _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:349:39)
#­47 _NativeSocket.connectToEventHandler.<anonymous closure> (dart:io-patch/socket_patch.dart:434:54)
#­48 _ReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:81:92)

Unhandled exception:
Bad state: No valid test. Did you forget to run your test inside a call to test()?
#­0 _DefaultZone.handleUncaughtError.<anonymous closure> (dart:async/zone.dart:132:7)
#­1 _asyncRunCallback (dart:async/event_loop.dart:9:15)
#­2 _asyncRunCallback (dart:async/event_loop.dart:13:7)
#­3 _createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:8:13)
#­4 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:95:21)
#­5 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:103:7)
#­6 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:103:7)
#­7 _Timer._createTimerHandler.<anonymous closure> (timer_impl.dart:111:23)
#­8 _ReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:81:92)

I posted an updated test on stack-overflow which and asked for the Dart version used.


Added NeedsInfo label.

@lrhn
Member
lrhn commented May 5, 2014

Added AssumedStale label.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment