Skip to content

WebSockets: Authentication of the HTTPS connection timed out #68399

@ThorstenReichert

Description

@ThorstenReichert

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

We have an ASP.NET Core 6.0 app, which accepts Websocket connections, pretty much exactly as described here. The server is configured for TLS and uses a self-signed certificate. The client app is a .NET Framework 4.8 WPF application, which uses System.Net.Websockets.ClientWebSocket to connect to the server like so:

var webSocket = new ClientWebSocket();
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
await webSocket.ConnectAsync(new Uri("wss://127.0.0.1:53535"));

On one particular PC, a good portion (~30%) of connection attempts fails. In those cases, we see on the server a debug log stating

2022-04-20 14:17:58.1692;Debug;Connection id "0HMH2OUO9VDRO" accepted.;
2022-04-20 14:17:58.1692;Debug;Connection id "0HMH2OUO9VDRO" started.;
2022-04-20 14:18:08.1890;Debug;Authentication of the HTTPS connection timed out.;
2022-04-20 14:18:08.1890;Debug;Connection id "0HMH2OUO9VDRO" stopped.;
2022-04-20 14:18:08.1890;Debug;Connection id "0HMH2OUO9VDRO" sending FIN because: "The Socket transport's send loop completed gracefully.";

And in the cases where connections go through, it feels like the time to connect varies wildly between pretty much immediately (as expected from a localhost connection) and multiple seconds. Though I could not find any indicators on which factors influence the time needed.
Between the start of the connection on the client and the authentication timeout on the server, none of our code is actually called (i.e. the WebSocket middleware on the server is not called).

The only standout-feature of that particular PC is, that it has two ethernet adapters and the issue seems to occur only when both are connected to something (one being a random, idle other PC, and one some external hardware, talking to which is the purpose of the WebSocket connection).

At this point I don't even have good ideas on what to try or look for, so any hints here would be much appreciated.

Expected Behavior

No response

Steps To Reproduce

None, unfortunately, since the issue only reproduces on one particular PC.

Exceptions (if any)

No exception on the server, on the client I see a bunch of FirstChanceExceptions. According to logfile timestamps, the first one happens after the timeout on the server is reached and reads:

System.Net.Sockets.SocketException (0x80004005): Eine bestehende Verbindung wurde softwaregesteuert
durch den Hostcomputer abgebrochen
   bei System.Net.Sockets.Socket.BeginReceive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state)

.NET Version

6.0.322

Anything else?

OS: Windows 10 21H1
Server app: ASP.NET Core 6.0, self-contained
Client app: .NET Framework 4.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Netneeds-author-actionAn issue or pull request that requires more info or actions from the author.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions