dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.21k stars 1.57k forks source link

http.get randomly throwing HttpException and HandshakeException when fetching from HTTPS #16768

Open DartBot opened 10 years ago

DartBot commented 10 years ago

This issue was originally filed by ben.pl...@gmail.com


What steps will reproduce the problem?

Here is roughly the code I am running. Its purpose is to download data from freebase about a bunch of movies. I am using Future.delayed to space the requests out over time (1/second), though it appears to happen more consistently if I make the interval small, say, 5/second.

void dartBugCode() {   var movieList = ['Movie Title A', 'Movie Title B', 'Movie C']; //thousands of items long   for (var i = 0; i < movieList.length; i++) {     var filmTitle = movieList[i];     new Future.delayed(new Duration(seconds: i), () {       var query = {         'type': '/film/film',         'name': filmTitle,         'mid': null       };       var queryString = JSON.encode(query);       queryString = Uri.encodeQueryComponent(queryString);       var url = 'https://www.googleapis.com/freebase/v1/mqlread?query=$queryString';       http.get(url).then((response) {         print(JSON.decode(response.body));       }, onError: (e, stackTrace) {         print(e);         print(stackTrace);       });     });   } }

What is the expected output? What do you see instead? I've run the same setup as above on different, non-SSL domains, and everything works as expected. However, over HTTPS, I get random exceptions thrown, either: "HandshakeException: Connection terminated during handshake" OR "HttpException: Connection closed before full header was received".

What version of the product are you using? On what operating system? Dart VM version: 1.2.0-dev.4.0 (Fri Feb 7 10:19:23 2014) on "macos_x64"

Please provide any additional information below. This appears to be similar to issue #15419, which was closed as "fixed", so perhaps this is related. Additionally, when these errors occur, they seem to happen in clumps, so 10 requests will happen normally and then all of a sudden 10 requests in a row will all fail rapidly.

kevmoo commented 10 years ago

Added Library-Html, Triaged labels.

lrhn commented 10 years ago

Added Area-HTML label.

sgjesse commented 10 years ago

This looks as if the remote host is terminating the connection. Could it be that the remote host is denying that many requests from one client? Have you tried to use wget/curl or some other meang to make the same requests?

I was not able to reproduce the issue locally. The returned response is:

  {result: null}

for all the requests If I change the movie title to something which is found I get a "real" result.

By adding the following line

  SecureSocket.initialize(useBuiltinRoots: false);

I could provoke a HandshakeException (HandshakeException: Handshake error in client (OS Error: Peer's Certificate issuer is not recognized., errno = -8179))

kevmoo commented 10 years ago

Removed Area-HTML label. Added Area-Library label.

efortuna commented 10 years ago

+1 for what Søren said. Closing as not a Dart problem. Please reopen/comment if you use wget/curl/some other language's httpRequest functionality at the same rate and do NOT get the same failure.


Set owner to @efortuna. Added Invalid label.

gusterwoei-veltra commented 6 years ago

It is very likely NOT the remote host problem. Having the same issue with my Flutter project. Calling the same API with Postman, curl, and Android java http lib, only the Flutter project hitting this issue, and the frequency is high.

kevmoo commented 6 years ago

@gusterwoei-veltra – can you reproduce this on a public endpoint we could validate?

itsJoKr commented 6 years ago

Same thing as @gusterwoei-veltra. Flutter app, using IOClient, and sometimes (randomly) I would get handshake exception. With Postman everything works fine.

kevmoo commented 6 years ago

Any hints on how to reproduce? Are you hitting an public API we could do a stress test against?

g-balas commented 5 years ago

Got this problem too : Stress test request from iOS and Android device on Flutter, with HTTPS, got random exception : HandshakeException: Connection terminated during handshake

I made myself a simple Flutter app to test this error and solved it, here my conclusion :

So... going back on this previous version for me !

I don't know why, but there is something specific in my web service that the last version of the dart http does not like.

muthufmass commented 5 years ago

Same happens on my flutter app too, getting HandshakeException and also it takes long time to respond back. We are at this moment planning alternative to right our own plugin calling native http call and get respond back as string & then convert to dart object on both android and ios.

Even example flutter code with dart doesnt work and throws handshake exception


import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

Future<Post> fetchPost() async {
  final response =
      await http.get('https://jsonplaceholder.typicode.com/posts/1');

  if (response.statusCode == 200) {
    // If the call to the server was successful, parse the JSON.
    return Post.fromJson(json.decode(response.body));
  } else {
    // If that call was not successful, throw an error.
    throw Exception('Failed to load post');
  }
}
vladms commented 4 years ago

Got this problem too : Stress test request from iOS and Android device on Flutter, with HTTPS, got random exception : HandshakeException: Connection terminated during handshake

I made myself a simple Flutter app to test this error and solved it, here my conclusion :

  • With http dart version 0.12.0+2 :

    • My Web Service works fine using a REST Client (Insomnia)
    • Everything is fine with an open HTTPS API (Tested with Nasa open HTTPS API)
    • But got random HandshakeException (about 1 / 25 request crash) with my web service
  • With http dart version 0.11.3+17 :

    • No crash, all good. (0 crash in more than 600 requests)

So... going back on this previous version for me !

I don't know why, but there is something specific in my web service that the last version of the dart http does not like.

Hy @g-balas . I am facing the same issue with handshake problem.. Donwgrading version to 0.11.3 fixes the problem, but using this version in Production is too risky because this version it is from 2016 . Do you managed to fix the issue other way ?

g-balas commented 4 years ago

@vladms I used the dart version 0.12.0+2 for one specific app that I pushed in prod, I did not updated this then, no problem reported. I am developing another app with the last version, and I got no problem. I can't tell why, but I think it was specific to my WS certificate configuration for my old app. You should look into that in my opinion.

elliotPopina commented 2 years ago

Hi every one, do you have any update for this problem ?

I actually encounter the same problem with the latest Flutter version on stable channel, and Dart 2.16.2.