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

TodoREST Sample Project “HttpRequestException: The Internet connection appears to be offline.” “Local network prohibited” on iOS 16 #12731

Closed
mdolfin opened this issue Jan 18, 2023 · 30 comments
Labels
platform/iOS 🍎 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working version/ios-16
Milestone

Comments

@mdolfin
Copy link

mdolfin commented Jan 18, 2023

Description

The TodoREST sample MAUI app project works on my old iPad not updated since iOS 15.3, but not on my iPhone on iOS 16.2 when configured to run against the included REST API project running on Windows on my local network. I have confirmed that the app has local network permission granted to it in the iOS settings. That is not the issue, despite what the error seems to be indicating.

Steps to Reproduce

  1. Configure the sample API project to run for your IP address on your local network, http, port 5000, and run that project.
  2. Configure the sample MAUI app project to run against that same IP, http, port, and run that on a local iOS 16 device on same local network.
  3. Confirm API works in Postman/Safari/Chrome, everything but the MAUI app.
  4. Use the debugger to confirm the errors caught trying to make API request are the one I am reporting even though you have given the app permissions to the local network in iOS settings.
  5. If you want, swap the iOS 16 device for one running iOS 15 and repeat the test. It works for me on iOS 15, not iOS 16, all else the exact same.

Expected outcome: The sample app is able successfully complete requests against the API.

Actual outcome: All requests fail on iOS 16.

Link to public reproduction project repository

https://github.com/dotnet/maui-samples/tree/main/7.0/WebServices/TodoREST

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 16

Did you find any workaround?

Using my iPad on iOS 15 for now.

Relevant log output

System.Net.Http.HttpRequestException: The Internet connection appears to be offline.
---> Foundation.NSErrorException: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x282683ea0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_NSURLErrorNWPathKey=unsatisfied (Local network prohibited), interface: en0[802.11], ipv4, _kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <C0EBA1B3-826E-45C3-8009-B88E0521BC83>.<2>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <C0EBA1B3-826E-45C3-8009-B88E0521BC83>.<2>"
), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=http://10.80.4.11:5000/api/todoitems/, NSErrorFailingURLKey=http://10.80.4.11:5000/api/todoitems/, _kCFStreamErrorDomainKey=1}
   --- End of inner exception stack trace ---
   at System.Net.Http.NSUrlSessionHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at TodoREST.Services.RestService.SaveTodoItemAsync(TodoItem item, Boolean isNewItem) in C:\PROJECTS\Yahara\Mobile\xTodoREST\TodoREST\Services\RestService.cs:line 68
@rachelkang
Copy link
Member

@mdolfin hi there - are you using http or https?

@rolfbjarne anything come to mind here with regard to iOS 16 differences?

@rachelkang rachelkang added the s/needs-info Issue needs more info from the author label Jan 18, 2023
@ghost
Copy link

ghost commented Jan 18, 2023

Hi @mdolfin. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@mdolfin
Copy link
Author

mdolfin commented Jan 18, 2023

@rachelkang I encounter the same error regardless of if I try to use http or https.

I have also tried setting the NSAllowsArbitraryLoads key in the Info.plist before posting this issue with no progress, but I will look at the links from rolfbjarne and try again and respond with what I find.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jan 18, 2023
@mdolfin
Copy link
Author

mdolfin commented Jan 18, 2023

It appears not to be related to App Transport Security.

Thank you for the info @rolfbjarne. If I understand correctly, replacing the NSAllowsLocalNetworking key with setting NSAllowsArbitraryLoads to true will completely disable App Transport Security (ATS) for all domains for the TodoREST sample. I have done that with no affect on the reported issue.

Thank you. Any other ideas?

@rolfbjarne
Copy link
Member

A couple of things to try to figure out where the network connection stops:

  • Configure the sample API project to run for your IP address on your local network, http, port 5000, and run that project.

Do you get the same error if you use the wrong port in the app? Or alternatively not start the server at all. This will show if there's an actual connection made to the server.

What if you a random hostname from the internet instead (say www.google.com), do you get the same error then? Maybe there's a difference between a local network and internet somehow.

@mdolfin
Copy link
Author

mdolfin commented Jan 19, 2023

Got some clues from that testing, @rolfbjarne, thank you. It seems to be behaving as though the local network permissions granted in iOS settings are being ignored on the device running iOS 16 that’s giving me the trouble.

I get a 404 Not Found when I use a random, valid hostname or IP from the internet. That is expected behavior, so the issue does appear to be isolated to local network.

I can also connect the iPhone to a completely different local network from the one the app is configured to find the server on, and I get a timeout rather than encountering the error. This is expected behavior, too, which is more evidence it is isolated to the local network.

I tried changing which local network I'm running the client and server on just to see if somehow the problem is isolated to the one network I've been testing on up until now. Exact same issue on that network.

I can reproduce the exact same error when the server is not running. So, it's erroring out before making a connection to the server. I can also reproduce by changing the IP in the app to one that is on the same network but is not in use (as if the server machine is off), and I can reproduce when I change the port to the wrong port in the app.

This error, BTW, is identical to the one I get the first time I run the sample app, before the user gives the app permission to use the Local Network in iOS. Even on the iOS 15 device (the one that works as expected), the first attempt to connect the server results in this very same error that's giving me trouble. But on the working device running iOS 15, subsequent attempts to connect to the server succeed as expected after the user has given permission to the app to use the local network. On the device updated to iOS 16, all attempts fail with the error even after permissions are given to the app in iOS settings. So, I assume the error is the normal error that we are supposed to get when the app doesn't have permission to use the local network. So, it appears to me to behave as if the local network permissions granted are being ignored on the iOS 16 for some reason.

Any ideas?

Thanks!

@rolfbjarne
Copy link
Member

Any ideas?

This is a wild shot, but try changing the bundle identifier to see if a different bundle identifier works. iOS identifies an app by the bundle identifier, and if you change it, iOS thinks it's a completely different app, so any old settings/stuff that might be cached/stored on disk will not be used.

Do you have another device with iOS 16 you can use to check if this problem is limited to a single device?

After that I guess the next step would be to try to re-create the problem in an Xcode sample, and if so, report the issue to Apple.

@mdolfin
Copy link
Author

mdolfin commented Jan 19, 2023

@rolfbjarne it's working now!?! Thank you so much for helping me think through this. I have no idea why it's working now, though.

I haven't changed anything. I wasn't working on this issue at all today. I was working on my real project that needs to create and consume a REST service. I got an API started and some code to TEST consuming it, and it worked on my iPad (with iOS 15) of course. When I was done for the day, I decided to try running that project on my iPhone (the one with iOS 16 giving me trouble), and it worked to my surprise.

At first I thought you might have been right about the bundle identifier since I got it working in a separate project with a different bundle identifier. So, I decided to reproduce the issue one more time with the TodoREST sample and then try to fix it by changing the bundle identifier, but I never got the chance to reproduce the error because somehow it is just working now!

It's still a mystery, I guess, but this can be closed. In any case it sounds like you are pretty confident this issue had nothing to do with MAUI/Xamarin and the next steps would have been to take the issue to Apple. I very much appreciate your helping me think through this. Thank you!

-Matt

@mdolfin mdolfin closed this as completed Jan 19, 2023
@mdolfin mdolfin reopened this Feb 18, 2023
@mdolfin
Copy link
Author

mdolfin commented Feb 18, 2023

The problem is back. New info: The problem only happens using Hot Restart. There is not a problem using a Mac build host (except for that being painfully slow.)

This is a different device now currently that I'm having the problem with. I got a new phone and have been using it for a couple of weeks. Suddenly, today, out of nowhere I receive the "Local network prohibited" error despite having changed nothing. It was working for weeks (on this very device). I deployed to the device several times this morning like normal while working on my project without error, and then suddenly I can not connect to my web API on the local network with this error every time as if I don't have permission granted to the local network. Of course I do have the permission in the iOS settings on the device. Same as before. This is the same weird issue.

ONE THING THAT DOES WORK: Remote deploy to the device using a Mac build host does work. I can switch back and forth in testing both my app project and the TodoREST sample between deploying remotely using the Mac and deploying locally using Hot Restart and it fails every time, both projects using Hot Restart and works every time, both projects using the Mac.

Hot Restart only seems to have the issue. Deleting the app doesn't work. Rebooting devices, restarting VS, cleaning, rebuilding, deleting bin and obj folders, changing the app name and bundle ID, nothing fixes it. I'm stuck again. Like I said, I can deploy using the Mac, but that is so painfully slow.

@rolfbjarne
Copy link
Member

This is rather puzzling.

Would it be possible to zip up the working (remotely built) and non-working (hot restart version) app bundles that are installed on the device?

@PureWeen PureWeen added the s/needs-info Issue needs more info from the author label Feb 23, 2023
@ghost
Copy link

ghost commented Feb 23, 2023

Hi @mdolfin. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@PureWeen PureWeen removed the s/needs-attention Issue has more information and needs another look label Feb 23, 2023
@mdolfin
Copy link
Author

mdolfin commented Feb 23, 2023

Well, the issue disappeared again by Monday. I'll upload the working and not working bundles if/when this happens again. Thanks.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Feb 23, 2023
@mdolfin
Copy link
Author

mdolfin commented Feb 25, 2023

The problem has returned again. What, exactly, would you like me to zip up? That is unclear to me. The .app file in the debug build output directory is incomplete. Is that normal? Where can I find the completed bundle with everything in it? Thank you.

@rolfbjarne
Copy link
Member

The problem has returned again. What, exactly, would you like me to zip up? That is unclear to me. The .app file in the debug build output directory is incomplete. Is that normal? Where can I find the completed bundle with everything in it? Thank you.

This will list the apps that have been built remotely on a Mac:

$ ls -d ~/Library/Caches/Xamarin/mtbs/builds/*/*/bin/Debug/net7.0-ios/ios-arm64/device-builds/*/*.app

and the Hot Restart builds from Windows are in %TEMP%\Xamarin\HotRestart\Signing (there should be an .ipa file inside a directory somewhere, that's the file to upload).

@PureWeen PureWeen added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Mar 2, 2023
@ghost
Copy link

ghost commented Mar 2, 2023

Hi @mdolfin. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost added the s/no-recent-activity Issue has had no recent activity label Mar 6, 2023
@ghost
Copy link

ghost commented Mar 6, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@CsabaStupak
Copy link

@mdolfin Have you been able to resolve this issue. I think I have similar problem #14224 . Unfortunately I could not check on different iOS version to confirm this is an iOS 16 issue.

@ghost ghost removed the s/no-recent-activity Issue has had no recent activity label Mar 30, 2023
@mdolfin
Copy link
Author

mdolfin commented Mar 30, 2023

I'll upload the working and not working bundles if/when this happens again. The issue disappeared on me again before I received the instructions on where to find the bundles to upload for you to look at.

I have not encountered this issue for some time now since I deleted all the MAUI debug apps I had loaded on the device. I have a few devices I test with, and this issue has only ever affected the one iPhone and then the new iPhone that I set up using an iCloud backup of the original one that was giving me trouble. There were several demo, tutorial, and practice MAUI apps that I had built and deployed to the device using Hot Restart and then never cleaned up. I cleaned them up now on both devices and the issue hasn't returned for some time. I still have no idea what the issue is/was, but maybe it was related to one of those somehow. I will reopen this ticket if it happens again.

@WisJamison
Copy link

I got the same issue on iPhone with iOS 16.3.1, but works good on iPad with iOS 15.

@ghost
Copy link

ghost commented Apr 10, 2023

Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!

@TeraForce
Copy link

TeraForce commented Apr 28, 2023

i got same problem (socketexception while Socket.Connect to a local network ip:port as #14224 , same error no route to host).
the local network permission is allowed (ios program settings), but it does not help this situlation.
i could ensure this port is opened, and both device (iphone and windows pc) are on same network. (also the socket connect code was used in about 5 years ago (that time it works, never got this issue), a very simple tcp connect application on ios, it was xarmarin.ios, same situlation local network, between a pc to a iphone

and i found the debugger never works (between my pc and iphone), using visual studio on windows, connect a mac in vmware, and mac connect to a iphone for run testing, but the visual studio on windows could not debug the program, it appears never connected (application on iphone crash never trigger any thing, breakpoint never hit, exit application on iphone would not stop the 'debug session', and press the stop debug button could hang visual studio for a long time, and never take effect). visual studio on windows usually auto disconnected to the mac. and every time i run a build on visual studio(windows), it has a big chance failed, in some case, clean the project output, then rebuild could help. but mostly case i need reboot the mac, and restart the visual studio(windows), then run build again (could be success). today i try to re-install the maui workload on visual studio (windows), also re-install the visual studio on mac. but still not solve the debug and build issue. (is that a common situlation or just happens on my side?)

@mattleibow
Copy link
Member

@rolfbjarne @steveisok @emaf is this maybe something to do with Hot Restart and the way the IDE communicates?

@mattleibow mattleibow added this to the Backlog milestone May 4, 2023
@ghost
Copy link

ghost commented May 4, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@rolfbjarne
Copy link
Member

@rolfbjarne @steveisok @emaf is this maybe something to do with Hot Restart and the way the IDE communicates?

I wonder if it's related to this somehow: https://developercommunity.visualstudio.com/t/HttpClient-behavior-in-NET-MAUI-iOS-app/10304297

@emaf
Copy link
Contributor

emaf commented May 8, 2023

@rolfbjarne Could it be for some reason for Hot Restart we fail to merge the manifests and so the needed settings are missing on the final app bundle?

@rolfbjarne
Copy link
Member

@rolfbjarne Could it be for some reason for Hot Restart we fail to merge the manifests and so the needed settings are missing on the final app bundle?

It could be, in which case the xcframework fix might have fixed this as well.

@jinxinjuan jinxinjuan added s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Jul 19, 2023
@ghost
Copy link

ghost commented Jul 19, 2023

Hi @mdolfin. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@jinxinjuan
Copy link

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 3.0(net8). Not repro on iOS platform with sample project.
maui-samples/tree/main/7.0/WebServices/TodoREST

@ghost ghost closed this as completed Jul 26, 2023
@nicjay
Copy link

nicjay commented Jul 27, 2023

Adding some data points:

A percentage of users of my enterprise application in production are experiencing this intermittently.

  • Occurs on iOS 16 only
  • Nothing to do with Hot Restart
  • Toggling phone WiFi off and on resolves it, sometimes.
  • The issue goes away on its own after a few days, sometimes.

I am trying to dig into it some more, which is proving tricky without knowing what changed for MAUI specifically in regard to iOS 16.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 26, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/iOS 🍎 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working version/ios-16
Projects
None yet
Development

No branches or pull requests