Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpClientRequest.abort() fails silently on web #40

Open
debaze opened this issue Jun 16, 2023 · 0 comments
Open

HttpClientRequest.abort() fails silently on web #40

debaze opened this issue Jun 16, 2023 · 0 comments

Comments

@debaze
Copy link

debaze commented Jun 16, 2023

Hi,
I'm trying to abort ongoing HTTP requests when a new route is pushed on top of the navigator route stack. However, on the web platform the abort() method on HttpClientRequest doesn't seem to cancel the request and doesn't throw.

I could reproduce the issue with the following sample:

import "dart:async";

import "package:flutter/material.dart";
import "package:universal_io/io.dart";

// Set the API URL here
const String baseUrl = "...";
const String endpoint = "...";

void main() {
  testNative();

  runApp(Container(color: Colors.black));
}

void testNative() async {
  final HttpClient client = newUniversalHttpClient();
  final Uri url = Uri.https(baseUrl, endpoint);
  final HttpClientRequest request = await client.postUrl(url);

  Timer(const Duration(milliseconds: 50), () {
    request.abort();

    debugPrint("abort");
  });

  request
      .close()
      .then(
        (_) => debugPrint("then()"),
        onError: (_) => debugPrint("onError()"),
      )
      .catchError(
        (_) => debugPrint("catchError()"),
      );
}

abort() is called before the request done future was completed, but it doesn't complete with an error.

Output of flutter doctor -v:

[✓] Flutter (Channel stable, 3.10.4, on Ubuntu 22.04.2 LTS 5.19.0-43-generic, locale en_US.UTF-8)
    • Flutter version 3.10.4 on channel stable at /home/keole/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 682aa387cf (10 days ago), 2023-06-05 18:04:56 -0500
    • Engine revision 2a3401c9bb
    • Dart version 3.0.3
    • DevTools version 2.23.1

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] VS Code (version 1.79.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.66.0

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension version 3.66.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.2 LTS 5.19.0-43-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 114.0.5735.133

[✓] Network resources
    • All expected network resources are available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant