dart-lang / dart-lang/http

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

Open
#366 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
1.1k
Forks
419
Avg merge
4d 14h
Merged PRs (30d)
8

Description

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:

```dart
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.
package:http/http.dart 166:20 _withClient
package:http/http.dart 46:5 get
test/http_repro_test.dart 18:11 main.
===== asynchronous gap ===========================
dart:async _asyncThenWrapperHelper
test/http_repro_test.dart main.

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

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction in test/http_repro_test.dart and trace the failure through package:http/src/byte_stream.dart, response.dart, and base_client.dart. Confirm the behavior when the server terminates the connection, then verify that the request invokes its error handling path instead of raising the reported type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.