chronoxor / NetCoreServer

Ultra fast and low latency asynchronous socket server & client C# .NET Core library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
https://chronoxor.github.io/NetCoreServer
MIT License
2.63k stars 550 forks source link

SslClient does not work in release mode #282

Closed pablogupi closed 7 months ago

pablogupi commented 7 months ago

Hello! I have a MAUI app with the NetCoreServer library and the SslClient implementation. In development it works correctly, but in release mode the app connects to the server, but the rest of the processes are no longer performed. A few seconds later, the application crashes because in the SslClient.cs, in line 361 _sslStream.ShutdownAsync().Wait(); the _sslStream is null. Next, in the catch, doing _sslStream.Dispose(); closes the application because _sslStream is still null and the exception is not handled.

try
{
    try
    {
        _sslStream.ShutdownAsync().Wait();
    }
    catch (Exception)
    {
    }
    _sslStream.Dispose();
    _sslStreamId = null;
    try
    {
        Socket.Shutdown(SocketShutdown.Both);
    }
    catch (SocketException)
    {
    }
    Socket.Close();
    Socket.Dispose();
    _connectEventArg.Dispose();
    IsSocketDisposed = true;
}
catch (ObjectDisposedException)
{
}
IsHandshaked = false;
IsConnected = false;
_receiving = false;
_sending = false;
ClearBuffers();

But I insist, in debug mode it works correctly and I don't have different configurations for debug or release. The server certificate is self-signed but it is the same for debug and release, so I don't think this is the problem. Does anyone know where the error can be?

Thanks a lot!