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

Create multiple Client implementations to solve different use cases #764

Closed
brianquinlan opened this issue Aug 18, 2022 · 8 comments
Closed
Assignees
Labels
type-enhancement A request for a change that isn't a bug

Comments

@brianquinlan
Copy link
Collaborator

brianquinlan commented Aug 18, 2022

This issue tracks the implementation of different package:http Client implementations.

Status

package:http_client_conformance_tests has been implemented but not released.

package:cupertino_http has been released as part of labs.dart.dev.

package:cronet_http is under development but has not been published

Background

The Dart ecosystem makes it difficult or impossible for users to access certain features desirable in an HTTP client e.g. HTTP 3 support, platform constructs (e.g. VPN, proxy and shared cookie support on iOS)

Where features are present in non-core packages, they present a novel interface that would require significant effort to adopt. For example, users wanting to use package:http2 would have to change their HTTP code completely when moving from the dart:io HttpClient.

Finally, it is difficult to contribute to dart:io HttpClient since modifying it requires understanding the Dart build process, navigating a Googler-only CI system, etc.

Solution

Allow developers to choose their own HTTP client implementation at runtime based on the platform, desired capabilities, etc.

The Dart team should develop HTTP implementations based on:

  • NSURLSession (available on iOS/MacOS, supports HTTP/1, HTTP/2, HTTP/3 and many iOS-specific features)
  • Cronet (available on all platforms, supports HTTP/1, HTTP/2, HTTP/3 and QUIC)
  • BoringSSL (existing dart:io HttpClient implementation, available on all platforms)

These implementations should support the package:http Client interface so that they can be used interchangeably.

There should be a conformance test that verifies that these implementations correctly implement the package:http Client interface.

@brianquinlan brianquinlan added the type-enhancement A request for a change that isn't a bug label Aug 18, 2022
@brianquinlan brianquinlan self-assigned this Aug 18, 2022
@feinstein
Copy link

feinstein commented Sep 6, 2022

Can we have some benchmarks showing the performance difference between the native http libraries and dart's current stable and universal solution?

@brianquinlan
Copy link
Collaborator Author

Hey @feinstein , I made an attempt to generate benchmarks but they were unconvincing. I would say that the native libraries have no clear advantages for sequential requests over reliable connections.

@feinstein
Copy link

Interesting... Thanks!

@lavinov-mercury
Copy link

Hi! Unfortunately, we are facing crash using cupertino_http. I couldn't find specific steps to reproduce it, for us it just happens sometimes after returning from the background or using Hot Restart. I tried to integrate it in 2 ways: with runWithClient (literally copied snippet from the README), and by replacing client in-place:

final _client = SentryHttpClient(
      client: Platform.isIOS
          ? CupertinoClient.defaultSessionConfiguration()
          : http.Client(),
      );

In both cases after some time playing around, i could face the following crash:

*** Assertion failure in -[CUPHTTPClientDelegate URLSession:dataTask:didReceiveResponse:completionHandler:], CUPHTTPClientDelegate.m:120
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Dart_PostCObject_DL failed.'
*** First throw call stack:
(0x181a1405c 0x199f2ef54 0x1832d599c 0x10532e10c 0x18220cc70 0x181684c04 0x181686950 0x18168e0ac 0x18168ec44 0x181699318 0x1f1e511b0 0x1f1e50f50)
libc++abi: terminating with uncaught exception of type NSException
* thread #65, queue = 'com.apple.NSURLSession-delegate', stop reason = signal SIGABRT
    frame #0: 0x00000001b84659c4 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
->  0x1b84659c4 <+8>:  b.lo   0x1b84659e4               ; <+40>
    0x1b84659c8 <+12>: pacibsp
    0x1b84659cc <+16>: stp    x29, x30, [sp, #-0x10]!
    0x1b84659d0 <+20>: mov    x29, sp
Target 0: (Runner) stopped.

@brianquinlan
Copy link
Collaborator Author

Hey @lavinov-mercury , thanks for the bug report. I refiled it as #785.

Would it be possible for you to add a snippet where you are actually making a call using the client?

@brianquinlan
Copy link
Collaborator Author

@lavinov-mercury This should be fixed in 0.0.6 - could you give it a try?

Hi! Unfortunately, we are facing crash using cupertino_http. I couldn't find specific steps to reproduce it, for us it just happens sometimes after returning from the background or using Hot Restart. I tried to integrate it in 2 ways: with runWithClient (literally copied snippet from the README), and by replacing client in-place:

final _client = SentryHttpClient(
      client: Platform.isIOS
          ? CupertinoClient.defaultSessionConfiguration()
          : http.Client(),
      );

In both cases after some time playing around, i could face the following crash:

*** Assertion failure in -[CUPHTTPClientDelegate URLSession:dataTask:didReceiveResponse:completionHandler:], CUPHTTPClientDelegate.m:120
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Dart_PostCObject_DL failed.'
*** First throw call stack:
(0x181a1405c 0x199f2ef54 0x1832d599c 0x10532e10c 0x18220cc70 0x181684c04 0x181686950 0x18168e0ac 0x18168ec44 0x181699318 0x1f1e511b0 0x1f1e50f50)
libc++abi: terminating with uncaught exception of type NSException
* thread #65, queue = 'com.apple.NSURLSession-delegate', stop reason = signal SIGABRT
    frame #0: 0x00000001b84659c4 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
->  0x1b84659c4 <+8>:  b.lo   0x1b84659e4               ; <+40>
    0x1b84659c8 <+12>: pacibsp
    0x1b84659cc <+16>: stp    x29, x30, [sp, #-0x10]!
    0x1b84659d0 <+20>: mov    x29, sp
Target 0: (Runner) stopped.

@duncaninsiris
Copy link

Hi!

Thanks for making this. I've been browsing the code and it looks like you don't support data uploads in the background. Is this something you intend to add in the near term?

Thank you!

@brianquinlan
Copy link
Collaborator Author

@duncaninsiris On what platform are you thinking? It might be possible to do this using the package:cupertino_http API but, AFAIK, Android does not support any special background downloading support in their http client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants