Who and how the terminal forcibly terminates the user sessions?

Good time of day.

Available Windows 2012 server running remotely under the virtualization environment Proxmox.
Recently faced with the problem of forced closure of user sessions.
Use the script:

query session >session.txt
for /f "skip=1 tokens=2" %%i in (session.txt) DO logoff %%i
del session.txt

Faithfully worked a lot of time, but the last 1-2 weeks the problems started.

Windows appears with error:
AFD
16002
"Closing TCP socket with local port number 3389 in the process 3316 running for longer than expected. The local port number may not be available until completion of close operation. This is usually due to incorrect network drivers. Make sure you have the latest Windows updates, and third-party network software, including network adapter drivers, firewalls or other security controls."

And then cannot connect to the server via RDP. It helps to restart the system.
June 3rd 19 at 19:17
2 answers
June 3rd 19 at 19:19
In user settings and RDP is possible to specify through what period of time the session is forced to end when idle. Also in the RDP server settings apply to all users of force, if not require different modes.
Or welcome to the habr
When a simple question is old and simple, but need a little more.
In the evening, say 20 or 21 hours - forced to throw out all users and to run some tasks for execution.
Now, the creaking of which I wrote above, until recently, worked on hurrah, but maybe that came with the latest updates or something. And the result is dull, shut-off of socket and the inability to connect again via RDP. Everything else works. - Randy_Klein65 commented on June 3rd 19 at 19:22
If I'm not mistaken there's also in the settings is possible to set the time + the days of the week when and from when to when the user can run\to connect to RDP. To limit the time needed Whatcom. - iliana.Beahan commented on June 3rd 19 at 19:25
June 3rd 19 at 19:21
One of the updates (big monthly), just the number 10, was the issue regarding the operation of the network. Fix it arrived on Thursday.

Find more questions by tags Windows ServerRDP