Discussion:
Thread counts increase, can not being terminated.
(too old to reply)
alper kamer
2008-06-22 11:55:33 UTC
Permalink
I Use Delphi 5 and Indy 9.0.50

I tested this problem with very simple program on windows 2003 server.

I put TidTCPserver component on my form. And I set DefaultPort value to 6710. And I set Maxconnection value to 1

And my simple code is below:

procedure TForm1.FormCreate(Sender: TObject);
begin
TCPserver.Active := true;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
TCPserver.Active := false;
end;

procedure TForm1.TCPserverExecute(AThread: TIdPeerThread);
var bb: byte;
begin
Athread.Connection.ReadBuffer( bb, sizeof( bb ) );
end;

And I run this program. I connectted this program with telnet program like this
run-->cmd
telnet 127.0.0.1 6710 --> I saw 4 threads on task manager for project1.exe program.
it's first value was 3.

I opened second window for telnet: run-->cmd-->
telnet 127.0.0.1 6710 -->I saw 5 threads on task manager for project1.exe program.
This connection was refused by server program but new thread can not been terminated.
I closed this telnet window.

I opened third window for telnet: run-->cmd-->
telnet 127.0.0.1 6710 -->I saw 6 threads on task manager for project1.exe program.
This connection was refused by server program but new thread can not been terminated.
I closed this telnet window.

So I am sure there is one problem in Indy 9.0.50
How can I solve this problem?
Remy Lebeau (TeamB)
2008-06-23 04:45:24 UTC
Permalink
Post by alper kamer
This connection was refused by server program but new thread
can not been terminated.
It should be. TIdTCPServer has explicit code to terminate and release the
thread:

--- IdTCPServer.pas ---

...
if (Server.MaxConnections > 0) and // Check MaxConnections
NOT
TIdThreadSafeList(Server.Threads).IsCountLessThan(Server.MaxConnections)
then begin
...
LPeer.WriteRFCReply(Server.MaxConnectionReply);
LPeer.Disconnect;
Server.ThreadMgr.ReleaseThread(LThread); // <-- here
end else begin
...


Gambit
alper kamer
2008-06-23 06:59:19 UTC
Permalink
Ok this code is same with my IdTCPServer.pas

// LastRcvTimeStamp := Now; // Added for session timeout support
// ProcessingTimeout := False;
if (Server.MaxConnections > 0) and // Check MaxConnections
NOT TIdThreadSafeList(Server.Threads).IsCountLessThan(Server.MaxConnections)
then begin
//Do not UpdateText here - in thread. Is done in constructor
LPeer.WriteRFCReply(Server.MaxConnectionReply);
LPeer.Disconnect;
Server.ThreadMgr.ReleaseThread(LThread); // Give the thread back to the thread-manager
end else begin
Server.Threads.Add(LThread); //APR
// Start Peer Thread
LThread.Start;
Break;
end;


What must I do? How can I solve this problem?
Post by Remy Lebeau (TeamB)
Post by alper kamer
This connection was refused by server program but new thread
can not been terminated.
It should be. TIdTCPServer has explicit code to terminate and release the
--- IdTCPServer.pas ---
...
if (Server.MaxConnections > 0) and // Check MaxConnections
NOT
TIdThreadSafeList(Server.Threads).IsCountLessThan(Server.MaxConnections)
then begin
...
LPeer.WriteRFCReply(Server.MaxConnectionReply);
LPeer.Disconnect;
Server.ThreadMgr.ReleaseThread(LThread); // <-- here
end else begin
...
Gambit
Loading...