dotnet / orleans

Cloud Native application framework for .NET
https://docs.microsoft.com/dotnet/orleans
MIT License
10.06k stars 2.03k forks source link

Client is rejecting when Client is from .NET Framework #6314

Closed RockNHawk closed 2 years ago

RockNHawk commented 4 years ago

Hi, I for forked from Sample Blazor proejct it works well and I add a .NET Framework web project with the same confuguration.

I if Client is .NET Core Web project, ClusterClient.Connect() works well, but if Client run on .NET Framework Web project, got this error:

Client is rejecting message: Request *cli/6d8736a5@b161089d->S127.0.0.1:30000:0*stg/17/00000011@S00000011 #2: . Reason = Retry count exceeded. Msg is: Request *cli/6d8736a5@b161089d->S127.0.0.1:30000:0*stg/17/00000011@S00000011 #2: 

and the Silo Console show the log:

The property accessor threw an exception: SocketException

The detail Silo log:

info: Orleans.Hosting.SiloHostedService[0]
    Orleans Silo started.
info: Microsoft.Orleans.Networking[0]
    Closing connection with remote endpoint 127.0.0.1:28625
[18:39:28 INF] Closing connection with remote endpoint 127.0.0.1:28625
info: Microsoft.Orleans.Networking[0]he property accessor threw 
    Connection Local: 127.0.0.1:30000, Remote: 127.0.0.1:28625, ConnectionId: 0HLTL4VVENOV2 terminated
[18:39:28 INF] Connection {
"ConnectionId": "0HLTL4VVENOV2",
"RemoteEndPoint": {
    "AddressFamily": "InterNetwork",
    "Address": {
        "AddressFamily": "InterNetwork",
        "ScopeId": "The property accessor threw an exception: SocketException",
        "IsIPv6Multicast": false,
        "IsIPv6LinkLocal": false,
        "IsIPv6SiteLocal": false,
        "IsIPv6Teredo": false,
        "IsIPv4MappedToIPv6": false,
        "Address": 16777343,
        "$type": "IPAddress"
    },
    "Port": 28625,
    "$type": "IPEndPoint"
},
"LocalEndPoint": {
    "AddressFamily": "InterNetwork",
    "Address": {
        "AddressFamily": "InterNetwork",
        "ScopeId": "The property accessor threw an exception: SocketException",
        "IsIPv6Multicast": false,
        "IsIPv6LinkLocal": false,
        "IsIPv6SiteLocal": false,
        "IsIPv6Teredo": false,
        "IsIPv4MappedToIPv6": false,
        "Address": 16777343,
        "$type": "IPAddress"
    },
    "Port": 30000,
    "$type": "IPEndPoint"
},
"IsValid": false,
"$type": "GatewayInboundConnection"

} terminated

I have searched but no related issue,How can I reslove this issue?

RockNHawk commented 4 years ago

I have create two Unit Test Project, one is .NET Core another is .NET Framework, the setup code is all the same, the .NET Core UnitTest works well, but .NET Framework fails with the same error as the above.

RockNHawk commented 4 years ago
Microsoft.Orleans.Networking: Information: Closing connection with remote endpoint 127.0.0.1:52774
Microsoft.Orleans.Networking: Information: Connection Local: 127.0.0.1:30000, Remote: 127.0.0.1:52774, ConnectionId: 0HLTL8QQET84J terminated
Exception thrown: 'System.Net.Sockets.SocketException' in System.Net.Primitives.dll
An exception of type 'System.Net.Sockets.SocketException' occurred in System.Net.Primitives.dll and wasn't handled before a managed/native boundary
The attempted operation is not supported for the type of object referenced.

StackTrace:

at System.Net.IPAddress.get_ScopeId()

image

RockNHawk commented 4 years ago

I have tested, this code cause the Exception:

var IP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1000);
IP.Address.ScopeId.ToString();

System.Net.Sockets.SocketException : The attempted operation is not supported for the type of object referenced
    at System.Net.IPAddress.get_ScopeId()

ScopeID is an IPv6 specific field. You have an IPv4 address. Therefore, an exception is raised. InterNetwork in this case means IPv4.

https://docs.microsoft.com/en-us/dotnet/api/system.net.ipaddress.scopeid?view=netframework-4.8

RockNHawk commented 4 years ago

Hi, I've debug the CallStack from the IPAddress.ScopeId, a Log of the Connection object cause the IPAddress.ScopeId call.

image

image

@benjaminpetit @sergeybykov

RockNHawk commented 4 years ago

ConnectionListener.cs

private async Task RunConnectionAsync(Connection connection)
{
  await Task.Yield();
  using (this.BeginConnectionScope(connection))
  {
    try
    {
      Task task = connection.Run();
      this.connections.TryAdd(connection, task);
      await task;
      this.trace.LogInformation("Connection {@Connection} terminated", (object) connection);
    }
    catch (Exception ex)
    {
      this.trace.LogInformation(ex, "Connection {@Connection} terminated with an exception", (object) connection);
    }
    finally
    {
      Task task;
      this.connections.TryRemove(connection, out task);
    }
  }
}
ReubenBond commented 4 years ago

Thanks for debugging, @RockNHawk! Could you submit a PR to fix this?

I think the easiest workaround for this is to log the connection as a string instead of logging it as a rich object (eg, by removing the '@' prefix in the logging code you pasted - and potentially in other, similar locations). The root issue seems to be in Serilog / System.Net, depending on how you look at it. Arguably, some objects just should not be passed to logging with the '@' specifier.

RockNHawk commented 4 years ago

Thanks for debugging, @RockNHawk! Could you submit a PR to fix this?

I think the easiest workaround for this is to log the connection as a string instead of logging it as a rich object (eg, by removing the '@' prefix in the logging code you pasted - and potentially in other, similar locations). The root issue seems to be in Serilog / System.Net, depending on how you look at it. Arguably, some objects just should not be passed to logging with the '@' specifier.

Thaky for you reply, I'm still debugging, Unfortunately this is not the root cause of the Client is rejecting error, seems an internal bug in Orleans.

RockNHawk commented 4 years ago

After I update the Orleans Silo project from Nuget 3.0.2 version to git source code master version c11be30, .NET Framework with ASP.NET Client works well, but .NET Framework UnitTest not work.