dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.95k stars 4.65k forks source link

Creating a System.Net.Sockets.Socket on iOS17 devices is not reliable and can crash the runtime #106587

Open amp64 opened 3 weeks ago

amp64 commented 3 weeks ago

Description

Sometimes when a socket is created the runtime crashes.

Reproduction Steps

private static void Test()
{
    try
    {
        IPAddress localIP;
        using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
        {
            socket.Connect("8.8.8.8", 65530);
            IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
            localIP = endPoint.Address;
        }

Expected behavior

For the socket to be created.

Actual behavior

After the socket constructor, I see in the output window:

08:08:20:170    Thread started: .NET Sockets #7
08:08:20:425     [0x1fd7f7ec0] The instruction pointer of the currently executing method(UPnP.Finder:Test ()) is not on the recorded stack. This is likely due to a runtime bug. The 2 frames are as follow: 
08:08:20:425     [0x1fd7f7ec0] Frame (0 / 2): (wrapper managed-to-native) System.Threading.Thread:StartInternal (System.Threading.Thread,int)
08:08:20:425    [0x1fd7f7ec0] Frame (1 / 2): System.Threading.Thread:StartCore ()

and then the app terminates.

Regression?

iOS 16 ok iOS 17 simulator ok iOS 17.5.1 device broken.

Known Workarounds

No response

Configuration

iPhone SE 3, iOS 17.51, .NET 8, Microsoft.iOS.Sdk/17.2.8053, using iOS17 SDK

Other information

No response

dotnet-policy-service[bot] commented 3 weeks ago

Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 3 weeks ago

Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @ivanpovazan, @steveisok, @akoeplinger See info in area-owners.md if you want to be subscribed.

jkurdek commented 1 week ago

@amp64 could you please share more details about this issue.

I have tried reproing it locally on iPhone 13 iOS 17.5.1 (through maui app and dotnet new iOS) and it did work correctly. You mentioned that this happens sometimes so I presume that the error is non-deterministic?

dotnet-policy-service[bot] commented 1 week ago

This issue has been marked needs-author-action and may be missing some important information.