I am having a strange problem with an SQL INSERT command. I'm inserting records using TMyQuery and for some reason a thread is being created for each insert but it seems that CloseHandle is not getting called to release the thread.
This can be seen by running SysInternals Process Explorer and looking at the handles in use. Normally only 3 threads run but with this problem a thread is created for every insert. This uses up resources and after a while MySQL will drop the connection and stop responding. If I exit my app and wait a while I can continue.
I am using BDS 2006 and MySQL 4.1.18 on XP Pro SP2. The odd thing about this is that it happens only on my laptop and not on my desktop. I am also seeing it on computers where we deploy the app. Using either the direct connect or libmySQL.dll causes the problem.
I did a stack trace to see where CreateThread was being called from. Here is the partial stack under libmySQL.dll:
TMySQLRecordset::ExecCommand
libmySQL.dll
kernel32.CreateThread
This is the stack using the direct connection:
TMySQLRecordset::ExecCommand
TMySQLConnection::Disconnect+0x14
TMySqlSession::Close+0x28
TMySqlVioTcp::Close
kernel32.CreateThread
This may be a MySQL or Windows problem, but I'm asking for help here because someone might know from prior experience what is happening. I have yet to try this on an older V3 MySQL.
James
TMyQuery->Execute() creates too many threads
Re: TMyQuery->Execute() creates too many threads
I finally had time to fully debug this problem. It turns out to be caused by F-Secure Internet Security 2006. It loads a winsock component winsflt.dll which is used to monitor TCP traffic. This DLL starts a thread on the closesocket call in the TMySqlVioTcp::Close method. The thread then calls ExitThread but there is no CloseHandle call to release the thread handle. After a while system resources get used up and both the client and MySQL will lock up. I will report this to F-Secure. Other security products use this DLL so this may be present on other computers. The partial fix is to not open and close the database as often as this opens up a new socket connection to MySQL each time and consumes a thread handle.