-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NetworkStream disposed #82
Comments
Hi, maybe a stack trace could help finding the cause of the issue. Disposing should only happen if the connection times out, I do not think that there is an Which version of FluentModbus do you use and how are you working with the client? Are you disposing the client maybe accidentially? |
I'm trying to get the stacktrace. Apart from this, the usage is something like this while (!token.IsCancellationRequested)
{
while (!client.IsConnected)
{
try
{
client.Connect();
}
catch (Exception e)
{
// log
}
await Task.Delay(Configuration.Polling, token);
}
try
{
// do stuff
}
catch (Exception e)
{
// log
}
await Task.Delay(Configuration.Polling, token);
resetCounter++;
if (resetCounter== resetMax)
{
resetCounter= 0;
client.Disconnect();
}
}
if (client.IsConnected)
{
client.Disconnect();
}
client.Dispose(); And, since the error is repeated continuously, there should not be accidental disposing I guess |
Hi @Apollo3zehn, we managed to corner the issue a bit more. After some tweaking, it's now a NullReferenceException inside the ModbusTcpClient while awaiting ReadHoldingRegistersAsync(unit, address, count, token)
where the parameters are:
and the session properties are:
This happens really randomly so it's really difficult to reproduce |
hi, when I quickly switch between server-side connection states, this problem may occur I did this FluentModbus.ModbusTcpClient client = null;
while (true)
{
try
{
if (client == null || !client.IsConnected)
{
Console.WriteLine("reconnect ...");
client = new FluentModbus.ModbusTcpClient();
client.Connect("127.0.0.1:502");
Thread.Sleep(200);
}
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message}");
continue;
}
try
{
var source = client.ReadHoldingRegisters<byte>(1, 40100, 10);
Console.WriteLine(BytesToString(source));
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message}");
client.Disconnect(); // Add this line
}
Thread.Sleep(50);
} |
Hi, we are using FluentModbus to connect 24/24 7/7 on a machine. The problem is, after some days of works the library fails with the NetworkStream disposed. Do you have any idea on when this could happen? I have no further informations as for now since it's difficult to reproduce, we'll try with continuous connections and disconnections to avoid the object being disposed
The text was updated successfully, but these errors were encountered: