http icon indicating copy to clipboard operation
http copied to clipboard

Type error thrown when making HTTP request and the connection is terminated

Open itsjoeconway opened this issue 5 years ago • 1 comments

This is either a regression in package version 0.12.0 or there is a tighter type check in Dart 2.7.0.

When making a request with this library, if the underlying connection is terminated, this package throws a type error instead of calling an error handler. A simple repro case and stack trace are included below:

import 'package:test/test.dart';
import 'package:http/http.dart' as http;
import 'dart:io';

void main() {
  test('http.get throws error if server connection is terminated during request', () async {
    final server = await HttpServer.bind(InternetAddress.anyIPv4, 9119);

    server.listen((onData) async {
      var socket = await onData.response.detachSocket();
      socket.destroy();
    });

    await http.get('http://localhost:9119');
  });
}
dart:async                                StreamView.listen
package:http/src/byte_stream.dart 23:5    ByteStream.toBytes
package:http/src/response.dart 64:40      Response.fromStream
package:http/src/base_client.dart 176:21  BaseClient._sendUnstreamed
===== asynchronous gap ===========================
dart:async                                _asyncThenWrapperHelper
package:http/src/base_client.dart         BaseClient._sendUnstreamed
package:http/src/base_client.dart 35:7    BaseClient.get
package:http/http.dart 46:36              get.<fn>
package:http/http.dart 166:20             _withClient
package:http/http.dart 46:5               get
test/http_repro_test.dart 18:11           main.<fn>
===== asynchronous gap ===========================
dart:async                                _asyncThenWrapperHelper
test/http_repro_test.dart                 main.<fn>

type '(HttpException) => Null' is not a subtype of type '(dynamic) => dynamic'

itsjoeconway avatar Jan 16 '20 00:01 itsjoeconway

Does this still reproduce? I'm not sure what could cause this.

natebosch avatar Jul 15 '21 22:07 natebosch