Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IdTcpServer Kick Client (Disconnect) INVALID HANDLE Exception
#4
(06-18-2020, 06:14 AM)3ddark Wrote: IoT Device or PC can suddenly shut down.

In this case, it seems that there is still a connection in Server Contexts.List (List.Count=1). Actually, List.Count=0

I want to disconnect connections and remove FDMemTables that do not send or receive data in the last 5 minutes.

Why are you trying to handle this in the main thread, and not in the individual connection threads? I would suggest setting up the tables and login in the OnConnect event, and logout and remove the tables in the OnDisconnect event, and then have the OnExecute event monitor connections, handle requests/responses, deal with timeouts, and disconnects as needed. You don't need to involve the main thread for any of this at all.

Also, there is no good reason to lock the server's Contexts list inside the OnExecute event when you are not actively enumerating active connections. You can freely use the AContext object inside the event without locking the list. Based on the code you have shown, that locking should be done only inside of your sendData() method instead, when passing data to another TIdContext to send.

Also, you should not be sharing DB components across thread boundaries at all. Your use of the DB queries is not thread-safe, multiple client threads can run queries at the same time, overwriting each other. You are not serializing access to the DB components at all.

Each client thread should use its own separate DB connection and query components. I would suggest using a pool of DB connections. When a given client thread wants to access the DB, it can pull an active DB connection from the pool (adding one if needed), run queries on that DB connection as needed, and then put it back in the pool for later reuse (and then have a separate thread that monitors the pool to close connections that have been idle for awhile).

(06-18-2020, 06:14 AM)3ddark Wrote: Debugger Exception Notification
---------------------------
Project LiftNetServer.exe raised exception class $C0000008 with message 'c0000008 INVALID_HANDLE'.
---------------------------

You didn't provide the call stack for the exception, like I asked for. I need to see EXACTLY where Disconnect() is causing the exception to be raised from.

Reply


Messages In This Thread
RE: IdTcpServer Kick Client (Disconnect) INVALID HANDLE Exception - by rlebeau - 06-19-2020, 12:25 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)