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

[ios] [CupertinoClient] http connection issue: nw_path_necp_check_for_updates Failed to copy updated result (22) #972

Open
delfme opened this issue Jun 26, 2023 · 8 comments
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@delfme
Copy link

delfme commented Jun 26, 2023

We are facing http connection issue when using CupertinoClient.

CC: @brianquinlan would you be so kind as to take a quick look at this? Just noticed you might know why this occurs.

To reproduce:

  • create a CupertinoClient as per code below
  • make http connection to whatever web api
  • http client will stall and console will print this error:
    console nw_path_necp_check_for_updates Failed to copy updated result (22)

Note: Issue occurs frequently if device is connected to Internet via a VPN.

It seems this issue occurred also in the past, maybe a regression?
flutter/flutter#111940

Code sample

Code is simple, as per instructions from http package Readme.
Use below ConnectionService.client to call whatever rest api on iOS.
Note: We needed to use CupertinoClient coz connectivity with standard dart client was pretty unstable.

class ConnectionService {
  static const String _debugPrefix = 'ConnectionService:';

  static final config = URLSessionConfiguration.ephemeralSessionConfiguration()
    ..allowsCellularAccess = false
    ..allowsConstrainedNetworkAccess = false
    ..allowsExpensiveNetworkAccess = false;

  // Initialize client. It will be CupertinoClient on iOS and IOClient on android
  static dynamic client = (Platform.isIOS) ? CupertinoClient.fromSessionConfiguration(config)
      : IOClient();

Logs

Error from console is: console nw_path_necp_check_for_updates Failed to copy updated result (22)
Note: We have this issue with both cupertino_http: 1.0.0 and 0.1.2

Flutter doctor

[✓] Flutter (Channel master, 3.12.0-7.0.pre.22, on macOS 12.6.5 21G531 darwin-arm64, locale en-IT)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
✗ cmdline-tools component is missing
Run path/to/sdkmanager --install "cmdline-tools;latest"
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run flutter doctor --android-licenses to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] Connected device (3 available)
[✓] Network resources

@delfme delfme added package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jun 26, 2023
@brianquinlan
Copy link
Collaborator

brianquinlan commented Jun 30, 2023

Hi @delfme ,

I'm not sure why this happens?

Does this happen while your app is in the foreground, background or both?

Do you have the com.apple.security.network.client entitlement set?

@delfme
Copy link
Author

delfme commented Jul 1, 2023

Hi @brianquinlan thx for the kind support!

It surely happens while app is in foreground. Couldn't check what happens with app in background.

I added com.apple.security.network.client to entitlement.
Couldn't find it from capabilities panel (is that a config. issue?), so added it manually to Runner.entitlements files (pic below). Is that the same?

Screenshot 2023-07-01 at 08 55 09 Screenshot 2023-07-01 at 08 55 21

Will test things and revert.

@brianquinlan
Copy link
Collaborator

Actually, the entitlement is not relevant for your configuration.

There isn't really much for me to use to diagnose the problem here. Do you see an error if you use IOClient?

@delfme
Copy link
Author

delfme commented Jul 6, 2023

Issue with IOClient was slow connection time on iOS and being a bit unstable.
That brought us to turn to CupertinoClient.

@delfme
Copy link
Author

delfme commented Jul 6, 2023

It would be great if CupertinoClient could be tested more under VPN and different network condition.
The feeling is that there is a minor bug that is somehow triggered by these conditions.

@brianquinlan
Copy link
Collaborator

Since CupertinoClient relies on Apple APIs for network transport, any bugs related to network conditions would most likely be related to those APIs.

Regarding #972 (comment) - I meant have you tested the scenario that demonstrates this bug using IOClient?

@andynewman10
Copy link

I am having the same issue. No http request is failing properly speaking, and I also see that keep-alive is working as expected.

Still, I can see there is an important slowdown when running my application, at least in debug mode (USB debugging).

Not sure it is related but - more worrying perhaps - I am sometimes seeing lots (and I say lots) of

[Client called nw_connection_copy_protocol_metadata_internal on unconnected nw_connection]

errors, as reported in the comments here:

https://stackoverflow.com/questions/76397964/client-called-nw-connection-copy-protocol-metadata-internal-on-unconnected-nw-co

My setup is described in the comments in the link above. I am using http 1.1.0.

I can't recall what triggered this new behavior.

@andynewman10
Copy link

andynewman10 commented Aug 27, 2023

Since CupertinoClient relies on Apple APIs for network transport, any bugs related to network conditions would most likely be related to those APIs.

Regarding #972 (comment) - I meant have you tested the scenario that demonstrates this bug using IOClient?

@brianquinlan Yes, there is the bug when simply using IOClient on iOS. I can reproduce the bug on iOS 16.6 with the following setup:

  • connecting to a LAN machine through plain http.
  • the HTTP server is hosted by a WAMP server on a Windows 11 machine that only has IPv4 enabled
  • the iOS device has both an IPv4 and IPv6 address.

To reproduce the problem, issue eg. 100 http requests with, say, a 1-second interval. From times to times, you will see the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants