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

The adapter isn't closing when the agent connession is missing #6

Open
lcicala opened this issue Mar 9, 2020 · 4 comments
Open

The adapter isn't closing when the agent connession is missing #6

lcicala opened this issue Mar 9, 2020 · 4 comments

Comments

@lcicala
Copy link

lcicala commented Mar 9, 2020

When the Stop method is called on an instance of the adapter there is a 20-second delay before continuing. After that the application continue running until its closing, but a library thread continue running and it doesn't allow the application to close completely, this issue does not permit the application to run again until the thread is killed by the task manager. This issue is only noticeable when the agent is missing.

@lcicala
Copy link
Author

lcicala commented Mar 9, 2020

The problem is in the mListenThread thread which calls the TcpListener.AcceptTcpListenerClient method that as reported on the Microsoft official documentation (https://docs.microsoft.com/en-US/dotnet/api/system.net.sockets.tcplistener.accepttcpclient?view=netframework-4.8) is a blocking call, so when the agent is missing the thread is blocked and never ending. The 20-second delay is caused by the Thread.Join method with a timeout of 20000ms called by the adapter Stop method; since the mListenThread is never ending the timeout is fully consumed and the execution continues.
In order to fix this issue the TcpListener.AcceptTcpClient call will be executed only when there are pending requests.

@hulinning2
Copy link

hulinning2 commented Mar 9, 2020

You should change to catch the exception since agent is out and the tcp will throw an error.
Once you are out the blocking call you can then start listening again.
Even agent is still connecting with adapter but Tcp connect could be dropped and create an exception so it would be able to catch an error here and start the listening again.

@wsobel
Copy link
Member

wsobel commented Mar 9, 2020 via email

lcicala pushed a commit to lcicala/dot_net_sdk that referenced this issue Mar 9, 2020
The mListenThread.AcceptTcpClient call is executed only if the mListenThread.Pending returns true in order to prevent the blocking call

Closes mtconnect#6
@lcicala
Copy link
Author

lcicala commented Jul 21, 2020

I've pushed a version that fixes this issue.

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