Discussion:
Terminate Thread Timeout - Simple steps to reproduction
(too old to reply)
Joel Harris
2003-09-19 14:42:05 UTC
Permalink
I posted this in the atozed forums a while back but either the forums are
messed up or my reader is.
Here are the simple steps to reproduce what appears to be a bug in
TIdTCPServer. Can anybody reproduce/confirm?
Am I crazy? This always causes me a Terminate Thread Timeout error when
shutting down the server while a client is connected.

1) Create an app with a TIdTCPServer component.
2) Set the IdTCPServer DefaultPort to whatever. Leave other properties as
default
3) In the IdTCPServer.Connect event handler do the following...
Coinitialize(nil); //requires unit ActiveX
AThread.Data := TMyDataModule.Create(nil); //TMyDataModule is created in
step 8
4) In the IdTCPServer.Disconnect event handler do this...
Couninitialize;//requires unit ActiveX as well
5) Create an event handler for the IdTCPServer.OnExecuteEvent and do
whatever inside it. I left it empty for testing purposes
6) In the form's OnCreate event handler set the IdTCPServer.Active property
to true.
7) In the form's OnDestroy event handler set the IdTCPServer.Active
property to false.
8) Now add a brand new data module to the project and name it MyDataModule.
No need to add anything to the data module.
9) Include the data module unit in your main unit's uses clause.

Create a simple client app to connect to the server. Run the server. Run
the client and connect it to the server. Then close the server. Boom. It
happens to me every time.

I am using Indy 9.0.14 and Delphi 7 on Windows XP
If anyone can tell me what is going wrong here I will appreciate it very
much.

Thanks.
Joel Harris
Ebbhead89


--
remove XYZ from contact address
Fredrik
2003-09-20 16:53:48 UTC
Permalink
Post by Joel Harris
I posted this in the atozed forums a while back but either the forums are
messed up or my reader is.
Here are the simple steps to reproduce what appears to be a bug in
TIdTCPServer. Can anybody reproduce/confirm?
Am I crazy? This always causes me a Terminate Thread Timeout error when
shutting down the server while a client is connected.
1) Create an app with a TIdTCPServer component.
2) Set the IdTCPServer DefaultPort to whatever. Leave other properties as
default
3) In the IdTCPServer.Connect event handler do the following...
Coinitialize(nil); //requires unit ActiveX
AThread.Data := TMyDataModule.Create(nil); //TMyDataModule is created in
step 8
4) In the IdTCPServer.Disconnect event handler do this...
Couninitialize;//requires unit ActiveX as well
5) Create an event handler for the IdTCPServer.OnExecuteEvent and do
whatever inside it. I left it empty for testing purposes
6) In the form's OnCreate event handler set the IdTCPServer.Active property
to true.
7) In the form's OnDestroy event handler set the IdTCPServer.Active
property to false.
8) Now add a brand new data module to the project and name it
MyDataModule.
Post by Joel Harris
No need to add anything to the data module.
9) Include the data module unit in your main unit's uses clause.
Create a simple client app to connect to the server. Run the server. Run
the client and connect it to the server. Then close the server. Boom.
It
Post by Joel Harris
happens to me every time.
I am using Indy 9.0.14 and Delphi 7 on Windows XP
If anyone can tell me what is going wrong here I will appreciate it very
much.
Thanks.
Joel Harris
Ebbhead89
Hi Joel,

I've had this problem alot as well.
I've never used the .Data property though.

Anyway, I started by setting up the app described above.
And I got the same error as you get.

Then I started tinkering alittle with the code.
In the OnExecute event I added the following:

AThread.Connection.CheckForDisconnect(False);
AThread.Connection.CheckForGracefulDisconnect(False);

It raises no exception, but will cause the socket to disconnect if the
client has disconnected,
and that will cause the OnDisconnect event to fire.
So in the OnDisconnect event I put the following:

AThread.Data.Free;
AThread.Data := Nil;

I tried without setting the Data property to Nil as well - but that still
gave me the timeout error.
Anyway - with these modifications I no longer recieve the Thread Timeout
exception.
trelloW_leachiM_tenesU
2003-09-24 15:36:52 UTC
Permalink
To avoid various error messages have a look at the functions of
"TCriticalSection". Just before you take action on VCL-Components
introduce this with initiated variable of "TCriticalFunction".Enter -
and finish it with "TCriticalFunction".Leave.

Hope this helps :)
Michael

Loading...