HttpClient crashes when using lantern VPN on Ubuntu.

  • Dart SDK Version (dart --version)
    Dart VM version: 2.5.0-dev.1.0 (Unknown timestamp) on “linux_x64”
  • OS: Ubuntu 18.04
  • Issue: flutter pub get error, reproduced by the following sample code.

Hi, Dart team,
I get an error when updating flutter sdk using flutter pub get. same issue as flutter/flutter#12301. I think the root cause may related to the dart:io package.

Here’s my analyze:

  1. I set up a Dart Command line app and reproduced the error:

import “dart:io”;
void main() {
var google = ““;
var client2 = HttpClient();
// same crash
// client2.findProxy = (uri) {
// return “PROXY”;
// };

// same crash
client2.findProxy = (url) {
return HttpClient.findProxyFromEnvironment(
url, environment: {“http_proxy”: “”, “https_proxy”: “”});

// no respond.
// client2.findProxy = HttpClient.findProxyFromEnvironment;
// no respond.
// client2.findProxy = null;

.then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
// Process the response.

  1. Error message is:

Unhandled exception: NoSuchMethodError: The setter 'readEventsEnabled=' was called on null. Receiver: null Tried calling: readEventsEnabled=false #0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1112:29) #1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21) #2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5) #3 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13) #4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)

  1. VPN settings:

I think this may related to my VPN environment settings. The following parameters are set automatically by Lantern VPN software.
`lixiang@lixiang-TM1701:~$ env | grep proxy


  1. curl is working.


  1. JAVA is working with proxy
    package com.tony.builder;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.ParseException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;


public class Main {

public static void main(String[] args) {
    String result = sendGet("");

public static String sendGet(String url) {
    HttpHost proxy = new HttpHost("", 45653, "http");

    RequestConfig defaultRequestConfig = RequestConfig.custom()

    CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();

    HttpGet httpget = new HttpGet(url);
    CloseableHttpResponse response = null;
    try {
        response = httpclient.execute(httpget);
    } catch (IOException e1) {
    String result = null;
    try {
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            result = EntityUtils.toString(entity);
    } catch (ParseException | IOException e) {
    } finally {
        try {
        } catch (IOException e) {
    return result;


Any ideas or suggestion will be helpful, thanks.

@sgjesse Maybe you have more ideas? thanks.

Author: Fantashit

3 thoughts on “HttpClient crashes when using lantern VPN on Ubuntu.

  1. Status update:
    Hi Dart team,
    I re-checked the issue and found that when _HttpParser received a lantern’s HttpRespond with empty body, it closed the HttpIncoming buffer, which I think it is reasonable behavior. But after that, the call back funtion located in _HttpClientConnection.send closed the socket, which is unconsiderable.

    I think at this point, I should check if it is a “CONNECT”‘s response and return directly if success.
    So I modified the code, only change 1 line in http_impl.dart. And in this way, HttpClient will behave the same using tinyproxy or lantern.

    Please check the patch atached.


  2. I’ve just started getting this issue in a Flutter project, due to an update to the Proxyman app on OSX.

    My Dart/Flutter details:

     Flutter (Channel beta, 1.18.0-11.1.pre, on Mac OS X 10.15.4 19E287, locale en-AU)
        • Flutter version 1.18.0-11.1.pre at /Users/athor/dev/flutter
        • Framework revision 2738a1148b (5 weeks ago), 2020-05-13 15:24:36 -0700
        • Engine revision ef9215ceb2
        • Dart version 2.9.0 (build 2.9.0-8.2.beta)

Comments are closed.