Skip to content
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

Exception "There is no valid request available" when any client reconnect. #138

Open
eryk955 opened this issue Nov 22, 2024 · 5 comments
Open

Comments

@eryk955
Copy link

eryk955 commented Nov 22, 2024

Hi
I have big problem with creating ModbusTCP Server. Server works, data flows, but when client reconnect (like PLC, because don't like to keep alive connection) FluentModbus call exception "System.Exception" and "There is no valid request available.". So in short, exception occurs, when any client tried to reconnect.

I checked this also on Node-Red ModbusTCP Client. Init connection is ok, but when Connected, VS call exception like above. I cannot find reason why this happens, so please, help :)

Tried also RequestValidator, but this cannot catch this problem. Problem still happens when Server is asynchronus.

Zrzut ekranu 2024-11-22 151142
Zrzut ekranu 2024-11-22 151200
Zrzut ekranu 2024-11-22 151407

@Apollo3zehn
Copy link
Owner

Hi, thanks for the bug report. Could you please provide also the stack trace of the exception? I would then see what methods were invoked before the exception happened. Thanks :-)

@eryk955
Copy link
Author

eryk955 commented Nov 22, 2024

Sure, here you go :)
Zrzut ekranu 2024-11-22 172421

@Apollo3zehn
Copy link
Owner

Thanks! I think the break; statement in the following line should be replaced with a return false;:

else
{
Length = 0;
break;
}

Why? Because this else block is only executed when the TCP connection has been closed and in that case the return value should be false. If it is true instead, the method WriteResponse is being invoked here:

if (await TryReceiveRequestAsync())
{
IsReady = true; // WriteResponse() can be called only when IsReady = true
if (ModbusServer.IsAsynchronous)
WriteResponse();
}

And if Length <= 0, it will throw the error you mentioned:

if (!(IsReady && Length > 0))
throw new Exception(ErrorMessage.ModbusTcpRequestHandler_NoValidRequestAvailable);

It would be great if you could try it with the above suggested fix :-)

@eryk955
Copy link
Author

eryk955 commented Nov 27, 2024

This seems to work, but another problem occured :)
Zrzut ekranu 2024-11-27 212912

@epasinetti
Copy link

Here same problem, in some cases the server Tcp stop working and connections from clients are not accepeted.
Also the connections counter is not very relayable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants