fix: Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Jonathan Arndt 2026-05-15 13:01:08 -07:00 committed by GitHub
parent c9f5af184b
commit b83af26b77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -225,30 +225,71 @@ namespace PepperDash.Core
return; return;
} }
var hostname = Hostname;
var port = Port;
var bufferSize = BufferSize;
UdpClient newClient = null;
CancellationTokenSource newReceiveCancellationTokenSource = null;
CancellationToken startReceiveToken = default(CancellationToken);
var shouldStartReceive = false;
lock (stateLock) lock (stateLock)
{ {
connectEnabled = true; connectEnabled = true;
if (client != null) if (client != null)
return; return;
}
try try
{
newReceiveCancellationTokenSource = new CancellationTokenSource();
newClient = new UdpClient();
newClient.Client.ReceiveBufferSize = bufferSize;
newClient.Client.SendBufferSize = bufferSize;
newClient.Connect(hostname, port);
lock (stateLock)
{ {
receiveCancellationTokenSource = new CancellationTokenSource(); if (!connectEnabled || client != null)
client = new UdpClient(); {
client.Client.ReceiveBufferSize = BufferSize; newClient.Close();
client.Client.SendBufferSize = BufferSize; newReceiveCancellationTokenSource.Cancel();
client.Connect(Hostname, Port); newReceiveCancellationTokenSource.Dispose();
return;
}
receiveCancellationTokenSource = newReceiveCancellationTokenSource;
client = newClient;
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED; ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
reconnectTimer.Change(ThreadingTimeout.Infinite, ThreadingTimeout.Infinite); reconnectTimer.Change(ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
StartReceive(receiveCancellationTokenSource.Token); startReceiveToken = receiveCancellationTokenSource.Token;
shouldStartReceive = true;
} }
catch (Exception ex)
if (shouldStartReceive)
StartReceive(startReceiveToken);
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Error connecting UDP client {0}", this, Key);
if (newClient != null)
newClient.Close();
if (newReceiveCancellationTokenSource != null)
{ {
Debug.LogMessage(ex, "Error connecting UDP client {0}", this, Key); newReceiveCancellationTokenSource.Cancel();
CleanupClient(); newReceiveCancellationTokenSource.Dispose();
ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT; }
StartReconnectTimer();
lock (stateLock)
{
if (connectEnabled && client == null)
{
ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
StartReconnectTimer();
}
} }
} }
} }